unnecessary-flutter-imports
- Group
- Correctness
- Path
lint/correctness/unnecessary-flutter-imports- Default
- On (recommended)
- Origin
- Falcon
- Domain
- flutter
- Rule
- 455 of 512
Disallow unused Flutter framework and dart:async imports.
Usage is based on resolved symbol identity and import combinators. Unknown unprefixed names conservatively keep an unrestricted import, avoiding guesses from capitalization or substrings.
Invalid
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart' as flutter show Text;
void main() {
print('Hello World');
}
class MyApp {
void doSomething() {
print('No Flutter symbols used');
}
}import 'package:flutter/material.dart';import 'package:flutter/material.dart';import 'package:flutter/foundation.dart';import 'package:flutter/foundation.dart';import 'dart:async';import 'dart:async';import 'package:flutter/services.dart';import 'package:flutter/services.dart';import 'package:flutter/widgets.dart';import 'package:flutter/widgets.dart';import 'package:flutter/material.dart' as flutter show Text;Valid
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'dart:async';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
home: Scaffold(
appBar: AppBar(title: const Text('Home')),
body: const Center(
child: Text('Hello'),
),
),
);
}
}
Future<void> asyncExample() async {
await Future.delayed(const Duration(seconds: 1));
debugPrint('Done');
}
// Uses Stream from dart:async
Stream<int> createStream() {
return Stream.fromIterable([1, 2, 3]);
}
// Uses widgets
Widget createButton() {
return ElevatedButton(
onPressed: () {},
child: const Text('Click me'),
);
}
// Uses Color from Flutter
void styleContainer() {
final container = Container(
color: Color.fromARGB(255, 100, 150, 200),
);
}Configure unnecessary-flutter-imports
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"unnecessary-flutter-imports": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/unnecessary-flutter-imports: <reason>More correctness rules
- unnecessary-nullable
check-unnecessary-nullablecross-fileFlags private function or method parameters whose nullable type is unnecessary.
- unnecessary-nullable-return-type
unnecessary_nullable_return_typeDisallow nullable return types on functions that never return null.
- unnecessary-statements
unnecessary_statementsrecommendedFlags expression statements whose expression has no clear effect.
- unrelated-type-equality-checks
unrelated_type_equality_checksrecommendedReports
==/!=comparisons and relational==/!=patterns whose operand types are unrelated. - unused-code
check-unused-codecross-fileReport public top-level declarations that nothing references.
- unused-dependenciescross-file
Report regular pubspec dependencies with no Dart import or export in the analyzed package.
- unused-files
check-unused-filescross-fileReport
lib/files that no project entrypoint can reach. - use-build-context-synchronously
use_build_context_synchronouslyrecommendedflutterFlags
BuildContextuse after an asynchronous gap without a mounted guard.