mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Samples maintenance (#435)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
include: package:pedantic/analysis_options.1.8.0.yaml
|
||||
include: package:pedantic/analysis_options.1.9.0.yaml
|
||||
|
||||
analyzer:
|
||||
strong-mode:
|
||||
|
||||
@@ -24,16 +24,17 @@ class AppModel<T> extends StatefulWidget {
|
||||
final T initialState;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
_AppModelState<T> createState() => _AppModelState<T>();
|
||||
|
||||
static T of<T>(BuildContext context) {
|
||||
final _AppModelScope<T> scope =
|
||||
final scope =
|
||||
context.dependOnInheritedWidgetOfExactType<_AppModelScope<T>>();
|
||||
return scope.appModelState.currentState;
|
||||
}
|
||||
|
||||
static void update<T>(BuildContext context, T newState) {
|
||||
final _AppModelScope<T> scope =
|
||||
final scope =
|
||||
context.dependOnInheritedWidgetOfExactType<_AppModelScope<T>>();
|
||||
scope.appModelState.updateState(newState);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class PlaceList extends StatefulWidget {
|
||||
}
|
||||
|
||||
class PlaceListState extends State<PlaceList> {
|
||||
ScrollController _scrollController = ScrollController();
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
void _onCategoryChanged(PlaceCategory newCategory) {
|
||||
_scrollController.jumpTo(0.0);
|
||||
@@ -107,7 +107,7 @@ class _PlaceListTile extends StatelessWidget {
|
||||
}).toList(),
|
||||
),
|
||||
Text(
|
||||
place.description != null ? place.description : '',
|
||||
place.description ?? '',
|
||||
style: Theme.of(context).textTheme.subtitle1,
|
||||
maxLines: 4,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
@@ -22,13 +22,16 @@ class PlaceMap extends StatefulWidget {
|
||||
}
|
||||
|
||||
class PlaceMapState extends State<PlaceMap> {
|
||||
static BitmapDescriptor _getPlaceMarkerIcon(PlaceCategory category) {
|
||||
static Future<BitmapDescriptor> _getPlaceMarkerIcon(
|
||||
BuildContext context, PlaceCategory category) async {
|
||||
switch (category) {
|
||||
case PlaceCategory.favorite:
|
||||
return BitmapDescriptor.fromAsset('assets/heart.png');
|
||||
return BitmapDescriptor.fromAssetImage(
|
||||
createLocalImageConfiguration(context), 'assets/heart.png');
|
||||
break;
|
||||
case PlaceCategory.visited:
|
||||
return BitmapDescriptor.fromAsset('assets/visited.png');
|
||||
return BitmapDescriptor.fromAssetImage(
|
||||
createLocalImageConfiguration(context), 'assets/visited.png');
|
||||
break;
|
||||
case PlaceCategory.wantToGo:
|
||||
default:
|
||||
@@ -47,7 +50,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
|
||||
LatLng _lastMapPosition;
|
||||
|
||||
Map<Marker, Place> _markedPlaces = Map<Marker, Place>();
|
||||
final Map<Marker, Place> _markedPlaces = <Marker, Place>{};
|
||||
|
||||
final Set<Marker> _markers = {};
|
||||
|
||||
@@ -61,10 +64,12 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
|
||||
// Draw initial place markers on creation so that we have something
|
||||
// interesting to look at.
|
||||
var markers = <Marker>{};
|
||||
for (var place in AppState.of(context).places) {
|
||||
markers.add(await _createPlaceMarker(context, place));
|
||||
}
|
||||
setState(() {
|
||||
for (Place place in AppState.of(context).places) {
|
||||
_markers.add(_createPlaceMarker(place));
|
||||
}
|
||||
_markers.addAll(markers);
|
||||
});
|
||||
|
||||
// Zoom to fit the initially selected category.
|
||||
@@ -76,7 +81,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
);
|
||||
}
|
||||
|
||||
Marker _createPlaceMarker(Place place) {
|
||||
Future<Marker> _createPlaceMarker(BuildContext context, Place place) async {
|
||||
final marker = Marker(
|
||||
markerId: MarkerId(place.latLng.toString()),
|
||||
position: place.latLng,
|
||||
@@ -85,7 +90,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
snippet: '${place.starRating} Star Rating',
|
||||
onTap: () => _pushPlaceDetailsScreen(place),
|
||||
),
|
||||
icon: _getPlaceMarkerIcon(place.category),
|
||||
icon: await _getPlaceMarkerIcon(context, place.category),
|
||||
visible: place.category == AppState.of(context).selectedCategory,
|
||||
);
|
||||
_markedPlaces[marker] = place;
|
||||
@@ -126,7 +131,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
}
|
||||
|
||||
void _updateExistingPlaceMarker({@required Place place}) {
|
||||
Marker marker = _markedPlaces.keys
|
||||
var marker = _markedPlaces.keys
|
||||
.singleWhere((value) => _markedPlaces[value].id == place.id);
|
||||
|
||||
setState(() {
|
||||
@@ -160,7 +165,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
|
||||
Future<void> _showPlacesForSelectedCategory(PlaceCategory category) async {
|
||||
setState(() {
|
||||
for (Marker marker in List.of(_markedPlaces.keys)) {
|
||||
for (var marker in List.of(_markedPlaces.keys)) {
|
||||
final place = _markedPlaces[marker];
|
||||
final updatedMarker = marker.copyWith(
|
||||
visibleParam: place.category == category,
|
||||
@@ -181,15 +186,15 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
}
|
||||
|
||||
Future<void> _zoomToFitPlaces(List<Place> places) async {
|
||||
GoogleMapController controller = await mapController.future;
|
||||
var controller = await mapController.future;
|
||||
|
||||
// Default min/max values to latitude and longitude of center.
|
||||
double minLat = widget.center.latitude;
|
||||
double maxLat = widget.center.latitude;
|
||||
double minLong = widget.center.longitude;
|
||||
double maxLong = widget.center.longitude;
|
||||
var minLat = widget.center.latitude;
|
||||
var maxLat = widget.center.latitude;
|
||||
var minLong = widget.center.longitude;
|
||||
var maxLong = widget.center.longitude;
|
||||
|
||||
for (Place place in places) {
|
||||
for (var place in places) {
|
||||
minLat = min(minLat, place.latitude);
|
||||
maxLat = max(maxLat, place.latitude);
|
||||
minLong = min(minLong, place.longitude);
|
||||
@@ -224,16 +229,19 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
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() as String,
|
||||
final newPlace = Place(
|
||||
id: Uuid().v1(),
|
||||
latLng: _pendingMarker.position,
|
||||
name: _pendingMarker.infoWindow.title,
|
||||
category: AppState.of(context).selectedCategory,
|
||||
);
|
||||
|
||||
var placeMarker = await _getPlaceMarkerIcon(
|
||||
context, AppState.of(context).selectedCategory);
|
||||
|
||||
setState(() {
|
||||
final updatedMarker = _pendingMarker.copyWith(
|
||||
iconParam: _getPlaceMarkerIcon(AppState.of(context).selectedCategory),
|
||||
iconParam: placeMarker,
|
||||
infoWindowParam: InfoWindow(
|
||||
title: 'New Place',
|
||||
snippet: null,
|
||||
@@ -267,7 +275,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
);
|
||||
|
||||
// Add the new place to the places stored in appState.
|
||||
final List<Place> newPlaces = List.from(AppState.of(context).places)
|
||||
final newPlaces = List<Place>.from(AppState.of(context).places)
|
||||
..add(newPlace);
|
||||
|
||||
// Manually update our map configuration here since our map is already
|
||||
@@ -292,7 +300,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
}
|
||||
|
||||
void _onToggleMapTypePressed() {
|
||||
final MapType nextType =
|
||||
final nextType =
|
||||
MapType.values[(_currentMapType.index + 1) % MapType.values.length];
|
||||
|
||||
setState(() {
|
||||
@@ -302,8 +310,7 @@ class PlaceMapState extends State<PlaceMap> {
|
||||
|
||||
Future<void> _maybeUpdateMapConfiguration() async {
|
||||
_configuration ??= MapConfiguration.of(AppState.of(context));
|
||||
final MapConfiguration newConfiguration =
|
||||
MapConfiguration.of(AppState.of(context));
|
||||
final newConfiguration = MapConfiguration.of(AppState.of(context));
|
||||
|
||||
// Since we manually update [_configuration] when place or selectedCategory
|
||||
// changes come from the [place_map], we should only enter this if statement
|
||||
|
||||
@@ -69,6 +69,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.7"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -80,7 +87,14 @@ packages:
|
||||
name: google_maps_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.0"
|
||||
version: "0.5.27+1"
|
||||
google_maps_flutter_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_maps_flutter_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
image:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -123,6 +137,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.4.0"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: plugin_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
quiver:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -156,6 +177,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
stream_transform:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_transform
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -190,7 +218,7 @@ packages:
|
||||
name: uuid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
version: "2.0.4"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -207,4 +235,4 @@ packages:
|
||||
version: "3.6.1"
|
||||
sdks:
|
||||
dart: ">=2.6.0 <3.0.0"
|
||||
flutter: ">=0.11.9 <2.0.0"
|
||||
flutter: ">=1.12.13+hotfix.5 <2.0.0"
|
||||
|
||||
@@ -11,13 +11,13 @@ dependencies:
|
||||
sdk: flutter
|
||||
|
||||
cupertino_icons: ^0.1.3
|
||||
google_maps_flutter: ^0.4.0
|
||||
uuid: ^1.0.3
|
||||
google_maps_flutter: ^0.5.27+1
|
||||
uuid: ^2.0.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
pedantic: ^1.8.0
|
||||
pedantic: ^1.9.0
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
|
||||
Reference in New Issue
Block a user