@@ -19,9 +19,9 @@ class MyApp extends StatelessWidget {
1919}
2020
2121class MyHomePage extends StatefulWidget {
22- MyHomePage ({Key key, this .title}) : super (key: key);
22+ MyHomePage ({Key ? key, this .title}) : super (key: key);
2323
24- final String title;
24+ final String ? title;
2525
2626 @override
2727 _MyHomePageState createState () => _MyHomePageState ();
@@ -36,7 +36,7 @@ class _MyHomePageState extends State<MyHomePage> {
3636 appBar: AppBar (
3737 // Here we take the value from the MyHomePage object that was created by
3838 // the App.build method, and use it to set our appbar title.
39- title: Text (widget.title),
39+ title: Text (widget.title ?? "" ),
4040 ),
4141 body: Center (
4242 // Center is a layout widget. It takes a single child and positions it
@@ -70,23 +70,48 @@ class _MyHomePageState extends State<MyHomePage> {
7070 return Container (
7171 padding: EdgeInsets .symmetric (horizontal: 20 ),
7272 child: GooglePlaceAutoCompleteTextField (
73- textEditingController: controller,
74- googleAPIKey: "YOUR_GOOGLE_API_KEY" ,
75- inputDecoration: InputDecoration (hintText: "Search your location" ),
76- debounceTime: 800 ,
77- countries: ["in" , "fr" ],
78- isLatLngRequired: true ,
79- getPlaceDetailWithLatLng: (Prediction prediction) {
80- print ("placeDetails" + prediction.lng.toString ());
81- },
82- itmClick: (Prediction prediction) {
83- controller.text = prediction.description;
73+ textEditingController: controller,
74+ googleAPIKey: "YOUR_GOOGLE_API_KEY" ,
75+ inputDecoration: InputDecoration (
76+ hintText: "Search your location" ,
77+ border: InputBorder .none,
78+ enabledBorder: InputBorder .none,
79+ ),
80+ debounceTime: 400 ,
81+ countries: ["in" , "fr" ],
82+ isLatLngRequired: false ,
83+ getPlaceDetailWithLatLng: (Prediction prediction) {
84+ print ("placeDetails" + prediction.lat.toString ());
85+ },
86+
87+ itemClick: (Prediction prediction) {
88+ controller.text = prediction.description ?? "" ;
89+ controller.selection = TextSelection .fromPosition (
90+ TextPosition (offset: prediction.description? .length ?? 0 ));
91+ },
92+ seperatedBuilder: Divider (),
93+ containerHorizontalPadding: 10 ,
94+
95+ // OPTIONAL// If you want to customize list view item builder
96+ itemBuilder: (context, index, Prediction prediction) {
97+ return Container (
98+ padding: EdgeInsets .all (10 ),
99+ child: Row (
100+ children: [
101+ Icon (Icons .location_on),
102+ SizedBox (
103+ width: 7 ,
104+ ),
105+ Expanded (child: Text ("${prediction .description ??"" }" ))
106+ ],
107+ ),
108+ );
109+ },
84110
85- controller.selection = TextSelection .fromPosition (
86- TextPosition (offset: prediction.description.length));
87- }
88- // default 600 ms ,
89- ),
111+ isCrossBtnShown: true ,
112+
113+ // default 600 ms ,
114+ ),
90115 );
91116 }
92117}
0 commit comments