diff --git a/place_tracker/analysis_options.yaml b/place_tracker/analysis_options.yaml index 1a52a34fc..f117e8a5f 100644 --- a/place_tracker/analysis_options.yaml +++ b/place_tracker/analysis_options.yaml @@ -1,10 +1,30 @@ +include: package:pedantic/analysis_options.yaml + analyzer: - errors: - # treat missing required parameters as a warning (not a hint) - missing_required_param: warning - # treat missing returns as a warning (not a hint) - missing_return: warning + strong-mode: + implicit-casts: false + implicit-dynamic: false linter: rules: - - unawaited_futures + - avoid_types_on_closure_parameters + - avoid_void_async + - await_only_futures + - camel_case_types + - cancel_subscriptions + - close_sinks + - constant_identifier_names + - control_flow_in_finally + - empty_statements + - hash_and_equals + - implementation_imports + - non_constant_identifier_names + - package_api_docs + - package_names + - package_prefixed_library_names + - test_types_in_equals + - throw_in_finally + - unnecessary_brace_in_string_interps + - unnecessary_getters_setters + - unnecessary_new + - unnecessary_statements diff --git a/place_tracker/lib/app_model.dart b/place_tracker/lib/app_model.dart index 4aa344214..d1c472441 100644 --- a/place_tracker/lib/app_model.dart +++ b/place_tracker/lib/app_model.dart @@ -26,19 +26,19 @@ class AppModel extends StatefulWidget { _AppModelState createState() => _AppModelState(); - static _typeOf() => T; + static Type _typeOf() => T; static T of(BuildContext context) { final Type appModelScopeType = _typeOf<_AppModelScope>(); - final _AppModelScope scope = - context.inheritFromWidgetOfExactType(appModelScopeType); + final _AppModelScope scope = context + .inheritFromWidgetOfExactType(appModelScopeType) as _AppModelScope; return scope.appModelState.currentState; } static void update(BuildContext context, T newState) { final Type appModelScopeType = _typeOf<_AppModelScope>(); - final _AppModelScope scope = - context.inheritFromWidgetOfExactType(appModelScopeType); + final _AppModelScope scope = context + .inheritFromWidgetOfExactType(appModelScopeType) as _AppModelScope; scope.appModelState.updateState(newState); } } diff --git a/place_tracker/lib/place_details.dart b/place_tracker/lib/place_details.dart index de7bf3edd..f8287aa7f 100644 --- a/place_tracker/lib/place_details.dart +++ b/place_tracker/lib/place_details.dart @@ -54,7 +54,7 @@ class PlaceDetailsState extends State { children: [ _NameTextField( controller: _nameController, - onChanged: (String value) { + onChanged: (value) { setState(() { _place = _place.copyWith(name: value); }); @@ -62,7 +62,7 @@ class PlaceDetailsState extends State { ), _DescriptionTextField( controller: _descriptionController, - onChanged: (String value) { + onChanged: (value) { setState(() { _place = _place.copyWith(description: value); }); @@ -70,7 +70,7 @@ class PlaceDetailsState extends State { ), _StarBar( rating: _place.starRating, - onChanged: (int value) { + onChanged: (value) { setState(() { _place = _place.copyWith(starRating: value); }); @@ -140,7 +140,7 @@ class _NameTextField extends StatelessWidget { style: const TextStyle(fontSize: 20.0, color: Colors.black87), autocorrect: true, controller: controller, - onChanged: (String value) { + onChanged: (value) { onChanged(value); }, ), @@ -173,7 +173,7 @@ class _DescriptionTextField extends StatelessWidget { maxLines: null, autocorrect: true, controller: controller, - onChanged: (String value) { + onChanged: (value) { onChanged(value); }, ), @@ -198,7 +198,7 @@ class _StarBar extends StatelessWidget { Widget build(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.center, - children: List.generate(maxStars, (int index) { + children: List.generate(maxStars, (index) { return IconButton( icon: const Icon(Icons.star), iconSize: 40.0, diff --git a/place_tracker/lib/place_list.dart b/place_tracker/lib/place_list.dart index de4059699..72f3a3224 100644 --- a/place_tracker/lib/place_list.dart +++ b/place_tracker/lib/place_list.dart @@ -21,9 +21,8 @@ class PlaceListState extends State { void _onPlaceChanged(Place value) { // Replace the place with the modified version. - final List newPlaces = List.from(AppState.of(context).places); - final int index = - newPlaces.indexWhere((Place place) => place.id == value.id); + final newPlaces = List.from(AppState.of(context).places); + final index = newPlaces.indexWhere((place) => place.id == value.id); newPlaces[index] = value; AppState.updateWith(context, places: newPlaces); @@ -44,11 +43,11 @@ class PlaceListState extends State { shrinkWrap: true, children: AppState.of(context) .places - .where((Place place) => + .where((place) => place.category == AppState.of(context).selectedCategory) - .map((Place place) => _PlaceListTile( + .map((place) => _PlaceListTile( place: place, - onPlaceChanged: (Place value) => _onPlaceChanged(value), + onPlaceChanged: (value) => _onPlaceChanged(value), )) .toList(), ), @@ -73,12 +72,12 @@ class _PlaceListTile extends StatelessWidget { @override Widget build(BuildContext context) { return InkWell( - onTap: () => Navigator.push( + onTap: () => Navigator.push( context, MaterialPageRoute(builder: (context) { return PlaceDetails( place: place, - onChanged: (Place value) => onPlaceChanged(value), + onChanged: (value) => onPlaceChanged(value), ); }), ), @@ -97,7 +96,7 @@ class _PlaceListTile extends StatelessWidget { maxLines: 3, ), Row( - children: List.generate(5, (int index) { + children: List.generate(5, (index) { return Icon( Icons.star, size: 28.0, diff --git a/place_tracker/lib/place_map.dart b/place_tracker/lib/place_map.dart index c9b923e58..4a5bee55e 100644 --- a/place_tracker/lib/place_map.dart +++ b/place_tracker/lib/place_map.dart @@ -38,7 +38,7 @@ class PlaceMapState extends State { static List _getPlacesForCategory( PlaceCategory category, List places) { - return places.where((Place place) => place.category == category).toList(); + return places.where((place) => place.category == category).toList(); } Completer mapController = Completer(); @@ -55,7 +55,7 @@ class PlaceMapState extends State { MapConfiguration _configuration; - void onMapCreated(GoogleMapController controller) async { + Future onMapCreated(GoogleMapController controller) async { mapController.complete(controller); _lastMapPosition = widget.center; @@ -95,12 +95,12 @@ class PlaceMapState extends State { void _pushPlaceDetailsScreen(Place place) { assert(place != null); - Navigator.push( + Navigator.push( context, MaterialPageRoute(builder: (context) { return PlaceDetails( place: place, - onChanged: (Place value) => _onPlaceChanged(value), + onChanged: (value) => _onPlaceChanged(value), ); }), ); @@ -108,9 +108,8 @@ class PlaceMapState extends State { void _onPlaceChanged(Place value) { // Replace the place with the modified version. - final List newPlaces = List.from(AppState.of(context).places); - final int index = - newPlaces.indexWhere((Place place) => place.id == value.id); + final newPlaces = List.from(AppState.of(context).places); + final index = newPlaces.indexWhere((place) => place.id == value.id); newPlaces[index] = value; _updateExistingPlaceMarker(place: value); @@ -128,7 +127,7 @@ class PlaceMapState extends State { void _updateExistingPlaceMarker({@required Place place}) { Marker marker = _markedPlaces.keys - .singleWhere((Marker value) => _markedPlaces[value].id == place.id); + .singleWhere((value) => _markedPlaces[value].id == place.id); setState(() { final updatedMarker = marker.copyWith( @@ -208,7 +207,7 @@ class PlaceMapState extends State { ); } - void _onAddPlacePressed() async { + Future _onAddPlacePressed() async { setState(() { final newMarker = Marker( markerId: MarkerId(_lastMapPosition.toString()), @@ -222,11 +221,11 @@ class PlaceMapState extends State { }); } - void _confirmAddPlace(BuildContext context) async { + Future _confirmAddPlace(BuildContext context) async { if (_pendingMarker != null) { // Create a new Place and map it to the marker we just added. final Place newPlace = Place( - id: Uuid().v1(), + id: Uuid().v1() as String, latLng: _pendingMarker.position, name: _pendingMarker.infoWindow.title, category: AppState.of(context).selectedCategory, @@ -321,8 +320,8 @@ class PlaceMapState extends State { // At this point, we know the places have been updated from the list // view. We need to reconfigure the map to respect the updates. newConfiguration.places - .where((Place p) => !_configuration.places.contains(p)) - .map((Place value) => _updateExistingPlaceMarker(place: value)); + .where((p) => !_configuration.places.contains(p)) + .map((value) => _updateExistingPlaceMarker(place: value)); await _zoomToFitPlaces( _getPlacesForCategory( @@ -339,7 +338,7 @@ class PlaceMapState extends State { Widget build(BuildContext context) { _maybeUpdateMapConfiguration(); - return Builder(builder: (BuildContext context) { + return Builder(builder: (context) { // We need this additional builder here so that we can pass its context to // _AddPlaceButtonBar's onSavePressed callback. This callback shows a // SnackBar and to do this, we need a build context that has Scaffold as @@ -559,9 +558,9 @@ class MapConfiguration { return false; } - final MapConfiguration otherConfiguration = other; - return otherConfiguration.places == places && - otherConfiguration.selectedCategory == selectedCategory; + return other is MapConfiguration && + other.places == places && + other.selectedCategory == selectedCategory; } static MapConfiguration of(AppState appState) { diff --git a/place_tracker/lib/place_tracker_app.dart b/place_tracker/lib/place_tracker_app.dart index 43f47f121..dde643242 100644 --- a/place_tracker/lib/place_tracker_app.dart +++ b/place_tracker/lib/place_tracker_app.dart @@ -23,7 +23,7 @@ class _PlaceTrackerAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( - builder: (BuildContext context, Widget child) { + builder: (context, child) { return AppModel( initialState: AppState(), child: child, @@ -137,10 +137,10 @@ class AppState { bool operator ==(Object other) { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; - final AppState otherAppState = other; - return otherAppState.places == places && - otherAppState.selectedCategory == selectedCategory && - otherAppState.viewType == viewType; + return other is AppState && + other.places == places && + other.selectedCategory == selectedCategory && + other.viewType == viewType; } @override diff --git a/place_tracker/pubspec.lock b/place_tracker/pubspec.lock index 0f97a1587..2de270f1e 100644 --- a/place_tracker/pubspec.lock +++ b/place_tracker/pubspec.lock @@ -89,7 +89,7 @@ packages: source: hosted version: "1.6.2" pedantic: - dependency: transitive + dependency: "direct dev" description: name: pedantic url: "https://pub.dartlang.org" @@ -171,5 +171,5 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.3.0-dev <3.0.0" flutter: ">=0.11.9 <2.0.0" diff --git a/place_tracker/pubspec.yaml b/place_tracker/pubspec.yaml index 0a55fb394..911531442 100644 --- a/place_tracker/pubspec.yaml +++ b/place_tracker/pubspec.yaml @@ -4,21 +4,20 @@ description: A new Flutter project. version: 1.0.0+1 environment: - sdk: ">=2.2.0 <3.0.0" + sdk: ">=2.3.0-dev <3.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^0.1.2 - google_maps_flutter: ^0.4.0 - - uuid: 1.0.3 + uuid: ^1.0.3 dev_dependencies: flutter_test: sdk: flutter + pedantic: ^1.5.0 flutter: assets: diff --git a/place_tracker/test/widget_test.dart b/place_tracker/test/widget_test.dart index 65c35a3e6..f1181b0c4 100644 --- a/place_tracker/test/widget_test.dart +++ b/place_tracker/test/widget_test.dart @@ -7,5 +7,5 @@ import 'package:flutter_test/flutter_test.dart'; void main() { - testWidgets('This test always passes', (WidgetTester tester) async {}); + testWidgets('This test always passes', (tester) async {}); }