mirror of
https://github.com/flutter/samples.git
synced 2026-04-28 02:18:47 +00:00
Analysis options, fixes and format (#106)
This commit is contained in:
@@ -26,19 +26,19 @@ class AppModel<T> extends StatefulWidget {
|
||||
|
||||
_AppModelState<T> createState() => _AppModelState<T>();
|
||||
|
||||
static _typeOf<T>() => T;
|
||||
static Type _typeOf<T>() => T;
|
||||
|
||||
static T of<T>(BuildContext context) {
|
||||
final Type appModelScopeType = _typeOf<_AppModelScope<T>>();
|
||||
final _AppModelScope<T> scope =
|
||||
context.inheritFromWidgetOfExactType(appModelScopeType);
|
||||
final _AppModelScope<T> scope = context
|
||||
.inheritFromWidgetOfExactType(appModelScopeType) as _AppModelScope<T>;
|
||||
return scope.appModelState.currentState;
|
||||
}
|
||||
|
||||
static void update<T>(BuildContext context, T newState) {
|
||||
final Type appModelScopeType = _typeOf<_AppModelScope<T>>();
|
||||
final _AppModelScope<T> scope =
|
||||
context.inheritFromWidgetOfExactType(appModelScopeType);
|
||||
final _AppModelScope<T> scope = context
|
||||
.inheritFromWidgetOfExactType(appModelScopeType) as _AppModelScope<T>;
|
||||
scope.appModelState.updateState(newState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class PlaceDetailsState extends State<PlaceDetails> {
|
||||
children: <Widget>[
|
||||
_NameTextField(
|
||||
controller: _nameController,
|
||||
onChanged: (String value) {
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_place = _place.copyWith(name: value);
|
||||
});
|
||||
@@ -62,7 +62,7 @@ class PlaceDetailsState extends State<PlaceDetails> {
|
||||
),
|
||||
_DescriptionTextField(
|
||||
controller: _descriptionController,
|
||||
onChanged: (String value) {
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_place = _place.copyWith(description: value);
|
||||
});
|
||||
@@ -70,7 +70,7 @@ class PlaceDetailsState extends State<PlaceDetails> {
|
||||
),
|
||||
_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,
|
||||
|
||||
@@ -21,9 +21,8 @@ class PlaceListState extends State<PlaceList> {
|
||||
|
||||
void _onPlaceChanged(Place value) {
|
||||
// Replace the place with the modified version.
|
||||
final List<Place> newPlaces = List.from(AppState.of(context).places);
|
||||
final int index =
|
||||
newPlaces.indexWhere((Place place) => place.id == value.id);
|
||||
final newPlaces = List<Place>.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<PlaceList> {
|
||||
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<void>(
|
||||
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,
|
||||
|
||||
@@ -38,7 +38,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
|
||||
static List<Place> _getPlacesForCategory(
|
||||
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();
|
||||
@@ -55,7 +55,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
|
||||
MapConfiguration _configuration;
|
||||
|
||||
void onMapCreated(GoogleMapController controller) async {
|
||||
Future<void> onMapCreated(GoogleMapController controller) async {
|
||||
mapController.complete(controller);
|
||||
_lastMapPosition = widget.center;
|
||||
|
||||
@@ -95,12 +95,12 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
void _pushPlaceDetailsScreen(Place place) {
|
||||
assert(place != null);
|
||||
|
||||
Navigator.push(
|
||||
Navigator.push<void>(
|
||||
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<PlaceMap> {
|
||||
|
||||
void _onPlaceChanged(Place value) {
|
||||
// Replace the place with the modified version.
|
||||
final List<Place> newPlaces = List.from(AppState.of(context).places);
|
||||
final int index =
|
||||
newPlaces.indexWhere((Place place) => place.id == value.id);
|
||||
final newPlaces = List<Place>.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<PlaceMap> {
|
||||
|
||||
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<PlaceMap> {
|
||||
);
|
||||
}
|
||||
|
||||
void _onAddPlacePressed() async {
|
||||
Future<void> _onAddPlacePressed() async {
|
||||
setState(() {
|
||||
final newMarker = Marker(
|
||||
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) {
|
||||
// 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<PlaceMap> {
|
||||
// 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<PlaceMap> {
|
||||
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) {
|
||||
|
||||
@@ -23,7 +23,7 @@ class _PlaceTrackerAppState extends State<PlaceTrackerApp> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
builder: (BuildContext context, Widget child) {
|
||||
builder: (context, child) {
|
||||
return AppModel<AppState>(
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user