Created
November 27, 2020 23:25
-
-
Save JosLuna98/51bbc786b969bda1a42663bd3d6cbfd1 to your computer and use it in GitHub Desktop.
implementation of route_search_box of address search field plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:address_search_field/address_search_field.dart'; | |
class Example extends StatelessWidget { | |
final _geoMethods = GeoMethods( | |
googleApiKey: 'GOOGLE_API_KEY', | |
language: 'es-419', | |
countryCode: 'ec', | |
country: 'Ecuador', | |
city: 'Esmeraldas', | |
); | |
final _origCtrl = TextEditingController(); | |
final _destCtrl = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Center( | |
child: RouteSearchBox( | |
geoMethods: geoMethods, | |
originIsMyLocation: true, | |
originCtrlr: _origCtrl, | |
destinationCtrlr: _destCtrl, | |
builder: (context, originBuilder, destinationBuilder, waypointBuilder, | |
{getDirections, waypointsMgr}) { | |
return Container( | |
padding: EdgeInsets.symmetric(horizontal: 15.0), | |
color: Colors.green[50], | |
height: 150.0, | |
child: Column( | |
children: [ | |
TextField( | |
controller: _origCtrl, | |
onTap: () => showDialog( | |
context: context, | |
builder: | |
(context) => | |
originBuilder.buildDefault( | |
builder: AddressDialogBuilder(), | |
onDone: (address) => null, | |
), | |
), | |
), | |
TextField( | |
controller: _destCtrl, | |
onTap: () => showDialog( | |
context: context, | |
builder: | |
(context) => | |
destinationBuilder.buildDefault( | |
builder: AddressDialogBuilder(), | |
onDone: (address) => null, | |
), | |
), | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
ElevatedButton( | |
child: Text('Waypoints'), | |
onPressed: () => Navigator.push( | |
context, | |
MaterialPageRoute( | |
fullscreenDialog: true, | |
builder: (context) => Waypoints( | |
waypointsMgr, waypointBuilder), | |
)), | |
), | |
ElevatedButton( | |
child: Text('Search'), | |
onPressed: () async { | |
try { | |
final result = await getDirections(); | |
print(result); | |
} catch (e) { | |
print(e); | |
} | |
}, | |
), | |
], | |
), | |
], | |
), | |
); | |
}, | |
), | |
), | |
); | |
} | |
} | |
class Waypoints extends StatelessWidget { | |
const Waypoints(this.waypointsMgr, this.waypointBuilder); | |
final WaypointsManager waypointsMgr; | |
final AddressSearchBuilder waypointBuilder; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
actions: [ | |
IconButton( | |
icon: Icon(Icons.add_location_alt), | |
onPressed: () => showDialog( | |
context: context, | |
builder: (context) => waypointBuilder.buildDefault( | |
builder: AddressDialogBuilder(), | |
onDone: (address) => null, | |
), | |
), | |
) | |
], | |
), | |
body: ValueListenableBuilder<List<Address>>( | |
valueListenable: waypointsMgr.valueNotifier, | |
builder: (context, value, _) => ListView.separated( | |
itemCount: value.length, | |
separatorBuilder: (BuildContext context, int index) => Divider(), | |
itemBuilder: (BuildContext context, int index) => | |
ListTile(title: Text(value[index].reference)), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment