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