diff --git a/add_to_app/fullscreen/flutter_module/analysis_options.yaml b/add_to_app/fullscreen/flutter_module/analysis_options.yaml new file mode 100644 index 000000000..85f6fbe91 --- /dev/null +++ b/add_to_app/fullscreen/flutter_module/analysis_options.yaml @@ -0,0 +1,19 @@ +include: package:flutter_lints/flutter.yaml + +analyzer: + strong-mode: + implicit-casts: false + implicit-dynamic: false + +linter: + rules: + avoid_types_on_closure_parameters: true + avoid_void_async: true + cancel_subscriptions: true + close_sinks: true + directives_ordering: true + package_api_docs: true + package_prefixed_library_names: true + test_types_in_equals: true + throw_in_finally: true + unnecessary_statements: true diff --git a/add_to_app/fullscreen/flutter_module/lib/main.dart b/add_to_app/fullscreen/flutter_module/lib/main.dart index d422c6762..5a2246e14 100644 --- a/add_to_app/fullscreen/flutter_module/lib/main.dart +++ b/add_to_app/fullscreen/flutter_module/lib/main.dart @@ -17,7 +17,7 @@ void main() { runApp( ChangeNotifierProvider.value( value: model, - child: MyApp(), + child: const MyApp(), ), ); } @@ -32,17 +32,17 @@ void main() { class CounterModel extends ChangeNotifier { CounterModel() { _channel.setMethodCallHandler(_handleMessage); - _channel.invokeMethod('requestCounter'); + _channel.invokeMethod('requestCounter'); } - final _channel = MethodChannel('dev.flutter.example/counter'); + final _channel = const MethodChannel('dev.flutter.example/counter'); int _count = 0; int get count => _count; void increment() { - _channel.invokeMethod('incrementCounter'); + _channel.invokeMethod('incrementCounter'); } Future _handleMessage(MethodCall call) async { @@ -58,13 +58,15 @@ class CounterModel extends ChangeNotifier { /// It offers two routes, one suitable for displaying as a full screen and /// another designed to be part of a larger UI.class MyApp extends StatelessWidget { class MyApp extends StatelessWidget { + const MyApp({Key key}) : super(key: key); + @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Module Title', routes: { - '/': (context) => FullScreenView(), - '/mini': (context) => Contents(), + '/': (context) => const FullScreenView(), + '/mini': (context) => const Contents(), }, ); } @@ -73,11 +75,13 @@ class MyApp extends StatelessWidget { /// Wraps [Contents] in a Material [Scaffold] so it looks correct when displayed /// full-screen. class FullScreenView extends StatelessWidget { + const FullScreenView({Key key}) : super(key: key); + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('Full-screen Flutter'), + title: const Text('Full-screen Flutter'), ), body: const Contents(showExit: true), ); @@ -92,7 +96,7 @@ class FullScreenView extends StatelessWidget { class Contents extends StatelessWidget { final bool showExit; - const Contents({this.showExit = false}); + const Contents({this.showExit = false, Key key}) : super(key: key); @override Widget build(BuildContext context) { @@ -108,7 +112,7 @@ class Contents extends StatelessWidget { ), ), ), - Positioned.fill( + const Positioned.fill( child: Opacity( opacity: .25, child: FittedBox( @@ -126,7 +130,7 @@ class Contents extends StatelessWidget { '${mediaInfo.size.height.toStringAsFixed(1)}', style: Theme.of(context).textTheme.headline5, ), - SizedBox(height: 16), + const SizedBox(height: 16), Consumer( builder: (context, model, child) { return Text( @@ -135,20 +139,20 @@ class Contents extends StatelessWidget { ); }, ), - SizedBox(height: 16), + const SizedBox(height: 16), Consumer( builder: (context, model, child) { return ElevatedButton( onPressed: () => model.increment(), - child: Text('Tap me!'), + child: const Text('Tap me!'), ); }, ), if (showExit) ...[ - SizedBox(height: 16), + const SizedBox(height: 16), ElevatedButton( onPressed: () => SystemNavigator.pop(animated: true), - child: Text('Exit this screen'), + child: const Text('Exit this screen'), ), ], ], diff --git a/add_to_app/fullscreen/flutter_module/pubspec.lock b/add_to_app/fullscreen/flutter_module/pubspec.lock index f3c6d303f..cc3b3bd49 100644 --- a/add_to_app/fullscreen/flutter_module/pubspec.lock +++ b/add_to_app/fullscreen/flutter_module/pubspec.lock @@ -88,6 +88,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" flutter_test: dependency: "direct dev" description: flutter @@ -98,6 +105,13 @@ packages: description: flutter source: sdk version: "0.0.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" matcher: dependency: transitive description: diff --git a/add_to_app/fullscreen/flutter_module/pubspec.yaml b/add_to_app/fullscreen/flutter_module/pubspec.yaml index b3b327b3a..ea9a4ba93 100644 --- a/add_to_app/fullscreen/flutter_module/pubspec.yaml +++ b/add_to_app/fullscreen/flutter_module/pubspec.yaml @@ -17,6 +17,7 @@ dev_dependencies: flutter_driver: sdk: flutter espresso: ^0.0.1+2 + flutter_lints: ^1.0.0 flutter: uses-material-design: true diff --git a/add_to_app/fullscreen/flutter_module/test/widget_test.dart b/add_to_app/fullscreen/flutter_module/test/widget_test.dart index 43ba66ba4..e16884a88 100644 --- a/add_to_app/fullscreen/flutter_module/test/widget_test.dart +++ b/add_to_app/fullscreen/flutter_module/test/widget_test.dart @@ -10,8 +10,10 @@ import 'package:provider/provider.dart'; class MockCounterModel extends ChangeNotifier implements CounterModel { int _count = 0; + @override int get count => _count; + @override void increment() { _count++; notifyListeners(); @@ -19,13 +21,13 @@ class MockCounterModel extends ChangeNotifier implements CounterModel { } void main() { - testWidgets('MiniView smoke test', (WidgetTester tester) async { + testWidgets('MiniView smoke test', (tester) async { // Build our app and trigger a frame. await tester.pumpWidget( MaterialApp( home: ChangeNotifierProvider.value( value: MockCounterModel(), - child: Contents(), + child: const Contents(), ), ), );