From 4ed3b1d535254be55b5d06f4c32ee34095000f1b Mon Sep 17 00:00:00 2001 From: Bwolfs2 Date: Sat, 16 May 2020 20:50:50 -0300 Subject: [PATCH 1/4] add option for custom floating buttom --- .../ios/Flutter/flutter_export_environment.sh | 11 +++ example/pubspec.lock | 28 +++--- lib/src/google_map_location_picker.dart | 70 ++++++------- lib/src/map.dart | 98 ++++++++++--------- pubspec.lock | 26 ++--- 5 files changed, 128 insertions(+), 105 deletions(-) create mode 100644 example/ios/Flutter/flutter_export_environment.sh diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100644 index 00000000..40ffe81d --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=C:\flutter" +export "FLUTTER_APPLICATION_PATH=D:\Testes\google_map_location_picker\example" +export "FLUTTER_TARGET=lib\main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build\ios" +export "OTHER_LDFLAGS=$(inherited) -framework Flutter" +export "FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1.0.0" diff --git a/example/pubspec.lock b/example/pubspec.lock index 8db3e862..56716a36 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -21,42 +21,42 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "2.0.11" + version: "2.0.13" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.2" + version: "1.6.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.4.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.12" convert: dependency: transitive description: @@ -70,7 +70,7 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "2.1.4" csslib: dependency: transitive description: @@ -155,7 +155,7 @@ packages: path: ".." relative: true source: path - version: "3.3.0" + version: "3.3.1" google_maps_flutter: dependency: transitive description: @@ -197,14 +197,14 @@ packages: name: image url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" + version: "2.1.12" intl: dependency: "direct main" description: name: intl url: "https://pub.dartlang.org" source: hosted - version: "0.16.0" + version: "0.16.1" intl_translation: dependency: "direct main" description: @@ -316,7 +316,7 @@ packages: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -328,7 +328,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" stack_trace: dependency: transitive description: @@ -370,7 +370,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.2.15" typed_data: dependency: transitive description: @@ -398,7 +398,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "3.6.1" yaml: dependency: transitive description: diff --git a/lib/src/google_map_location_picker.dart b/lib/src/google_map_location_picker.dart index 3cd7428e..c8f170bd 100644 --- a/lib/src/google_map_location_picker.dart +++ b/lib/src/google_map_location_picker.dart @@ -18,23 +18,22 @@ import 'model/nearby_place.dart'; import 'utils/location_utils.dart'; class LocationPicker extends StatefulWidget { - LocationPicker( - this.apiKey, { - Key key, - this.initialCenter, - this.requiredGPS, - this.myLocationButtonEnabled, - this.layersButtonEnabled, - this.automaticallyAnimateToCurrentLocation, - this.mapStylePath, - this.appBarColor, - this.searchBarBoxDecoration, - this.hintText, - this.resultCardConfirmIcon, - this.resultCardAlignment, - this.resultCardDecoration, - this.resultCardPadding, - }); + LocationPicker(this.apiKey, + {Key key, + this.initialCenter, + this.requiredGPS, + this.myLocationButtonEnabled, + this.layersButtonEnabled, + this.automaticallyAnimateToCurrentLocation, + this.mapStylePath, + this.appBarColor, + this.searchBarBoxDecoration, + this.hintText, + this.resultCardConfirmIcon, + this.resultCardAlignment, + this.resultCardDecoration, + this.resultCardPadding, + this.customLocationCard}); final String apiKey; @@ -54,6 +53,8 @@ class LocationPicker extends StatefulWidget { final Alignment resultCardAlignment; final Decoration resultCardDecoration; final EdgeInsets resultCardPadding; + final Function(BuildContext context, LocationProvider locationProvider) + customLocationCard; @override LocationPickerState createState() => LocationPickerState(); @@ -391,6 +392,7 @@ class LocationPickerState extends State { resultCardDecoration: widget.resultCardDecoration, resultCardPadding: widget.resultCardPadding, key: mapKey, + customLocationCard: widget.customLocationCard, ), ); }), @@ -408,23 +410,22 @@ class LocationPickerState extends State { /// set [automaticallyAnimateToCurrentLocation] to false. /// /// -Future showLocationPicker( - BuildContext context, - String apiKey, { - LatLng initialCenter = const LatLng(45.521563, -122.677433), - bool requiredGPS = true, - bool myLocationButtonEnabled = false, - bool layersButtonEnabled = false, - bool automaticallyAnimateToCurrentLocation = true, - String mapStylePath, - Color appBarColor = Colors.transparent, - BoxDecoration searchBarBoxDecoration, - String hintText, - Widget resultCardConfirmIcon, - AlignmentGeometry resultCardAlignment, - EdgeInsetsGeometry resultCardPadding, - Decoration resultCardDecoration, -}) async { +Future showLocationPicker(BuildContext context, String apiKey, + {LatLng initialCenter = const LatLng(45.521563, -122.677433), + bool requiredGPS = true, + bool myLocationButtonEnabled = false, + bool layersButtonEnabled = false, + bool automaticallyAnimateToCurrentLocation = true, + String mapStylePath, + Color appBarColor = Colors.transparent, + BoxDecoration searchBarBoxDecoration, + String hintText, + Widget resultCardConfirmIcon, + AlignmentGeometry resultCardAlignment, + EdgeInsetsGeometry resultCardPadding, + Decoration resultCardDecoration, + Function(BuildContext context, LocationProvider locationProvider) + customLocationCard}) async { final results = await Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext context) { @@ -444,6 +445,7 @@ Future showLocationPicker( resultCardAlignment: resultCardAlignment, resultCardPadding: resultCardPadding, resultCardDecoration: resultCardDecoration, + customLocationCard: customLocationCard, ); }, ), diff --git a/lib/src/map.dart b/lib/src/map.dart index bec73684..404f2ad4 100644 --- a/lib/src/map.dart +++ b/lib/src/map.dart @@ -35,6 +35,7 @@ class MapPicker extends StatefulWidget { this.resultCardAlignment, this.resultCardDecoration, this.resultCardPadding, + this.customLocationCard, }) : super(key: key); final String apiKey; @@ -55,6 +56,8 @@ class MapPicker extends StatefulWidget { final Alignment resultCardAlignment; final Decoration resultCardDecoration; final EdgeInsets resultCardPadding; + final Function(BuildContext context, LocationProvider locationProvider) + customLocationCard; @override MapPickerState createState() => MapPickerState(); @@ -198,52 +201,59 @@ class MapPickerState extends State { alignment: widget.resultCardAlignment ?? Alignment.bottomCenter, child: Padding( padding: widget.resultCardPadding ?? EdgeInsets.all(16.0), - child: Card( - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), - child: Consumer( - builder: (context, locationProvider, _) { - return Padding( - padding: const EdgeInsets.all(16.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - flex: 20, - child: FutureLoadingBuilder( - future: getAddress(locationProvider.lastIdleLocation), - mutable: true, - loadingIndicator: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CircularProgressIndicator(), - ], + child: widget.customLocationCard != null + ? Consumer( + builder: (context, locationProvider, _) { + return widget.customLocationCard(context, locationProvider); + }) + : Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8)), + child: Consumer( + builder: (context, locationProvider, _) { + return Padding( + padding: const EdgeInsets.all(16.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + flex: 20, + child: FutureLoadingBuilder( + future: + getAddress(locationProvider.lastIdleLocation), + mutable: true, + loadingIndicator: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircularProgressIndicator(), + ], + ), + builder: (context, address) { + _address = address; + return Text( + address ?? 'Unnamed place', + style: TextStyle(fontSize: 18), + ); + }), ), - builder: (context, address) { - _address = address; - return Text( - address ?? 'Unnamed place', - style: TextStyle(fontSize: 18), - ); - }), - ), - Spacer(), - FloatingActionButton( - onPressed: () { - Navigator.of(context).pop({ - 'location': LocationResult( - latLng: locationProvider.lastIdleLocation, - address: _address, - ) - }); - }, - child: widget.resultCardConfirmIcon ?? - Icon(Icons.arrow_forward), - ), - ], + Spacer(), + FloatingActionButton( + onPressed: () { + Navigator.of(context).pop({ + 'location': LocationResult( + latLng: locationProvider.lastIdleLocation, + address: _address, + ) + }); + }, + child: widget.resultCardConfirmIcon ?? + Icon(Icons.arrow_forward), + ), + ], + ), + ); + }), ), - ); - }), - ), ), ); } diff --git a/pubspec.lock b/pubspec.lock index 2d93bd56..98569a66 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,42 +21,42 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "2.0.11" + version: "2.0.13" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.5.2" + version: "1.6.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.4.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.12" convert: dependency: transitive description: @@ -70,7 +70,7 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "2.1.4" csslib: dependency: transitive description: @@ -183,14 +183,14 @@ packages: name: image url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" + version: "2.1.12" intl: dependency: "direct main" description: name: intl url: "https://pub.dartlang.org" source: hosted - version: "0.16.0" + version: "0.16.1" intl_translation: dependency: "direct main" description: @@ -302,7 +302,7 @@ packages: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -314,7 +314,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" stack_trace: dependency: "direct main" description: @@ -356,7 +356,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.2.15" typed_data: dependency: transitive description: @@ -384,7 +384,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "3.6.1" yaml: dependency: transitive description: From e355553087de76a2bb263728c52182c8ef9ac374 Mon Sep 17 00:00:00 2001 From: Bwolfs2 Date: Sat, 16 May 2020 21:41:19 -0300 Subject: [PATCH 2/4] add appbar option to search --- example/lib/main.dart | 3 +- lib/src/google_map_location_picker.dart | 98 ++++++++++++++----------- 2 files changed, 55 insertions(+), 46 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index b1c8c83f..265ab5d6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,7 +3,6 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:google_map_location_picker/generated/i18n.dart' as location_picker; import 'package:google_map_location_picker/google_map_location_picker.dart'; -import 'package:google_map_location_picker_example/keys.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'generated/i18n.dart'; @@ -49,7 +48,7 @@ class _MyAppState extends State { onPressed: () async { LocationResult result = await showLocationPicker( context, - apiKey, + "Your Api Key", initialCenter: LatLng(31.1975844, 29.9598339), // automaticallyAnimateToCurrentLocation: true, // mapStylePath: 'assets/mapStyle.json', diff --git a/lib/src/google_map_location_picker.dart b/lib/src/google_map_location_picker.dart index c8f170bd..24a6adff 100644 --- a/lib/src/google_map_location_picker.dart +++ b/lib/src/google_map_location_picker.dart @@ -18,22 +18,25 @@ import 'model/nearby_place.dart'; import 'utils/location_utils.dart'; class LocationPicker extends StatefulWidget { - LocationPicker(this.apiKey, - {Key key, - this.initialCenter, - this.requiredGPS, - this.myLocationButtonEnabled, - this.layersButtonEnabled, - this.automaticallyAnimateToCurrentLocation, - this.mapStylePath, - this.appBarColor, - this.searchBarBoxDecoration, - this.hintText, - this.resultCardConfirmIcon, - this.resultCardAlignment, - this.resultCardDecoration, - this.resultCardPadding, - this.customLocationCard}); + LocationPicker( + this.apiKey, { + Key key, + this.initialCenter, + this.requiredGPS, + this.myLocationButtonEnabled, + this.layersButtonEnabled, + this.automaticallyAnimateToCurrentLocation, + this.mapStylePath, + this.appBarColor, + this.searchBarBoxDecoration, + this.hintText, + this.resultCardConfirmIcon, + this.resultCardAlignment, + this.resultCardDecoration, + this.resultCardPadding, + this.customLocationCard, + this.appBar, + }); final String apiKey; @@ -53,6 +56,7 @@ class LocationPicker extends StatefulWidget { final Alignment resultCardAlignment; final Decoration resultCardDecoration; final EdgeInsets resultCardPadding; + final AppBar appBar; final Function(BuildContext context, LocationProvider locationProvider) customLocationCard; @@ -363,18 +367,19 @@ class LocationPickerState extends State { child: Builder(builder: (context) { return Scaffold( extendBodyBehindAppBar: true, - appBar: AppBar( - iconTheme: Theme.of(context).iconTheme, - elevation: 0, - backgroundColor: widget.appBarColor, - key: appBarKey, - title: SearchInput( - (input) => searchPlace(input), - key: searchInputKey, - boxDecoration: widget.searchBarBoxDecoration, - hintText: widget.hintText, - ), - ), + appBar: widget.appBar ?? + AppBar( + iconTheme: Theme.of(context).iconTheme, + elevation: 0, + backgroundColor: widget.appBarColor, + key: appBarKey, + title: SearchInput( + (input) => searchPlace(input), + key: searchInputKey, + boxDecoration: widget.searchBarBoxDecoration, + hintText: widget.hintText, + ), + ), body: MapPicker( widget.apiKey, initialCenter: widget.initialCenter, @@ -410,22 +415,26 @@ class LocationPickerState extends State { /// set [automaticallyAnimateToCurrentLocation] to false. /// /// -Future showLocationPicker(BuildContext context, String apiKey, - {LatLng initialCenter = const LatLng(45.521563, -122.677433), - bool requiredGPS = true, - bool myLocationButtonEnabled = false, - bool layersButtonEnabled = false, - bool automaticallyAnimateToCurrentLocation = true, - String mapStylePath, - Color appBarColor = Colors.transparent, - BoxDecoration searchBarBoxDecoration, - String hintText, - Widget resultCardConfirmIcon, - AlignmentGeometry resultCardAlignment, - EdgeInsetsGeometry resultCardPadding, - Decoration resultCardDecoration, - Function(BuildContext context, LocationProvider locationProvider) - customLocationCard}) async { +Future showLocationPicker( + BuildContext context, + String apiKey, { + LatLng initialCenter = const LatLng(45.521563, -122.677433), + bool requiredGPS = true, + bool myLocationButtonEnabled = false, + bool layersButtonEnabled = false, + bool automaticallyAnimateToCurrentLocation = true, + String mapStylePath, + Color appBarColor = Colors.transparent, + BoxDecoration searchBarBoxDecoration, + String hintText, + Widget resultCardConfirmIcon, + AlignmentGeometry resultCardAlignment, + EdgeInsetsGeometry resultCardPadding, + Decoration resultCardDecoration, + Function(BuildContext context, LocationProvider locationProvider) + customLocationCard, + AppBar appBar, +}) async { final results = await Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext context) { @@ -446,6 +455,7 @@ Future showLocationPicker(BuildContext context, String apiKey, resultCardPadding: resultCardPadding, resultCardDecoration: resultCardDecoration, customLocationCard: customLocationCard, + appBar: appBar, ); }, ), From 293c990282044a54ddc1aaf52ea8d6f721ad17b1 Mon Sep 17 00:00:00 2001 From: Bwolfs2 Date: Sun, 17 May 2020 21:34:32 -0300 Subject: [PATCH 3/4] add a custom Pin --- lib/src/google_map_location_picker.dart | 6 +++++- lib/src/map.dart | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/google_map_location_picker.dart b/lib/src/google_map_location_picker.dart index 24a6adff..519dd86d 100644 --- a/lib/src/google_map_location_picker.dart +++ b/lib/src/google_map_location_picker.dart @@ -36,6 +36,7 @@ class LocationPicker extends StatefulWidget { this.resultCardPadding, this.customLocationCard, this.appBar, + this.customPin, }); final String apiKey; @@ -59,7 +60,7 @@ class LocationPicker extends StatefulWidget { final AppBar appBar; final Function(BuildContext context, LocationProvider locationProvider) customLocationCard; - + final Function customPin; @override LocationPickerState createState() => LocationPickerState(); } @@ -398,6 +399,7 @@ class LocationPickerState extends State { resultCardPadding: widget.resultCardPadding, key: mapKey, customLocationCard: widget.customLocationCard, + customPin: widget.customPin, ), ); }), @@ -433,6 +435,7 @@ Future showLocationPicker( Decoration resultCardDecoration, Function(BuildContext context, LocationProvider locationProvider) customLocationCard, + Function customPin, AppBar appBar, }) async { final results = await Navigator.of(context).push( @@ -456,6 +459,7 @@ Future showLocationPicker( resultCardDecoration: resultCardDecoration, customLocationCard: customLocationCard, appBar: appBar, + customPin: customPin, ); }, ), diff --git a/lib/src/map.dart b/lib/src/map.dart index 404f2ad4..96e81d4f 100644 --- a/lib/src/map.dart +++ b/lib/src/map.dart @@ -36,6 +36,7 @@ class MapPicker extends StatefulWidget { this.resultCardDecoration, this.resultCardPadding, this.customLocationCard, + this.customPin, }) : super(key: key); final String apiKey; @@ -59,6 +60,8 @@ class MapPicker extends StatefulWidget { final Function(BuildContext context, LocationProvider locationProvider) customLocationCard; + final Function customPin; + @override MapPickerState createState() => MapPickerState(); } @@ -189,7 +192,7 @@ class MapPickerState extends State { onToggleMapTypePressed: _onToggleMapTypePressed, onMyLocationPressed: _initCurrentLocation, ), - pin(), + widget.customPin == null ? widget.customPin() : pin(), locationCard(), ], ), From 704b40948b92e9c4c967c13274a4928f6338b61d Mon Sep 17 00:00:00 2001 From: Bwolfs2 Date: Sun, 17 May 2020 21:43:18 -0300 Subject: [PATCH 4/4] change function to Widget --- lib/src/google_map_location_picker.dart | 4 ++-- lib/src/map.dart | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/google_map_location_picker.dart b/lib/src/google_map_location_picker.dart index 519dd86d..0257b753 100644 --- a/lib/src/google_map_location_picker.dart +++ b/lib/src/google_map_location_picker.dart @@ -60,7 +60,7 @@ class LocationPicker extends StatefulWidget { final AppBar appBar; final Function(BuildContext context, LocationProvider locationProvider) customLocationCard; - final Function customPin; + final Widget customPin; @override LocationPickerState createState() => LocationPickerState(); } @@ -435,7 +435,7 @@ Future showLocationPicker( Decoration resultCardDecoration, Function(BuildContext context, LocationProvider locationProvider) customLocationCard, - Function customPin, + Widget customPin, AppBar appBar, }) async { final results = await Navigator.of(context).push( diff --git a/lib/src/map.dart b/lib/src/map.dart index 96e81d4f..a041378d 100644 --- a/lib/src/map.dart +++ b/lib/src/map.dart @@ -60,7 +60,7 @@ class MapPicker extends StatefulWidget { final Function(BuildContext context, LocationProvider locationProvider) customLocationCard; - final Function customPin; + final Widget customPin; @override MapPickerState createState() => MapPickerState(); @@ -192,7 +192,7 @@ class MapPickerState extends State { onToggleMapTypePressed: _onToggleMapTypePressed, onMyLocationPressed: _initCurrentLocation, ), - widget.customPin == null ? widget.customPin() : pin(), + widget.customPin ?? pin(), locationCard(), ], ),