avoid-web-libraries-in-flutter

Same as avoid_web_libraries_in_flutter in Dart lints

Path
lint/correctness/avoid-web-libraries-in-flutter
Default
On (recommended)
Origin
Dart lints
Domain
flutter
Rule
188 of 512
recommendedflutter

Disallow importing web-only dart: libraries from Flutter code.

Applies only to packages depending on Flutter, excluding Flutter web plugins. The legacy dart:html, dart:js, and dart:js_util imports are checked; modern JS interop libraries are allowed by the upstream lint.

Invalid

example.dartdart
// Bad: imports of web-only dart libraries.
import 'dart:html';
import 'dart:js';
import 'dart:js_util';

void main() {}
Avoid using web-only libraries in Flutter code; they are not portable across platforms.
1// Bad: imports of web-only dart libraries.
2import 'dart:html';
Avoid using web-only libraries in Flutter code; they are not portable across platforms.
2import 'dart:html';
3import 'dart:js';
Avoid using web-only libraries in Flutter code; they are not portable across platforms.
3import 'dart:js';
4import 'dart:js_util';

Valid

example.dartdart
// Good: portable imports with no web-only libraries.
import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:http/http.dart';

void main() {}

Configure avoid-web-libraries-in-flutter

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "avoid-web-libraries-in-flutter": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/avoid-web-libraries-in-flutter: <reason>
  • await-only-futuresawait_only_futuresrecommended

    Await only values assignable to futures; FutureOr, dynamic, bottom types and extension types are accepted like the analyzer.

  • banned-importscross-file

    Report imports forbidden by package-relative architectural boundaries.

  • cancel-subscriptionscancel_subscriptionsrecommended

    Cancel instances of dart:async StreamSubscription.

  • check-is-not-closed-after-async-gaprecommendedbloc

    Flags Bloc add and emit calls after an await without a fresh isClosed check.

  • close-sinksclose_sinksrecommended

    Close instances of dart:core Sink.

  • collection-methods-unrelated-typecollection_methods_unrelated_typerecommended

    Reports collection lookups whose argument type is unrelated to the collection's type argument.

  • comment-referencescomment_referencesrecommended

    Flags doc-comment references [name] that resolve to nothing in scope.

  • correct-order-for-super-disposecorrect_order_for_super_disposerecommendedflutter

    Require super.dispose() to be the last call in dispose.