-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.dart
141 lines (129 loc) · 4.28 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import 'package:flutter/material.dart';
import 'package:map_autocomplete_field/map_autocomplete_field.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
final TextEditingController addressCtrl = TextEditingController();
final String yourMapApiKey = '';
/// The [MapAutoCompleteField] widget is used here just as any other in a Material App
/// This sample showcases the barest minimum required to use the Widget.
///
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(builder: (context) {
return Scaffold(
appBar: AppBar(
title: const Text('MapTypeAheadField Demo'),
),
body: Padding(
padding: const EdgeInsets.all(25),
child: Column(
children: [
MapAutoCompleteField(
googleMapApiKey: yourMapApiKey,
controller: addressCtrl,
itemBuilder: (BuildContext context, suggestion) {
return ListTile(
title: Text(suggestion.description),
);
},
onSuggestionSelected: (suggestion) {
addressCtrl.text = suggestion.description;
},
),
TextButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SecondScreen()));
},
child: Text('Go to Next'))
],
),
),
);
}),
);
}
}
class SecondScreen extends StatelessWidget {
SecondScreen({Key? key}) : super(key: key);
/// [addressCtrl] : [TextEditingController] for the MapAutoComplete widget
final TextEditingController addressCtrl = TextEditingController();
/// [yourApiKey] : Your Google Places API key
final String yourApiKey = '';
/// The [MapAutoCompleteField] widget is used here just as any other in a Material App
/// This sample showcases the widget with a more robust configuration mostly through the [InputDecoration] parameter.
///
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('MapTypeAheadField Alt'),
),
body: Padding(
padding: const EdgeInsets.all(25),
child: MapAutoCompleteField(
googleMapApiKey: yourApiKey,
controller: addressCtrl,
itemBuilder: (BuildContext context, suggestion) {
return ListTile(
leading: Icon(Icons.add),
title: Text(suggestion.description),
);
},
onSuggestionSelected: (suggestion) {
addressCtrl.text = suggestion.description;
},
inputDecoration: const InputDecoration(
icon: Icon(Icons.add),
prefixIcon: Icon(Icons.remove),
suffixIcon: Icon(Icons.access_time_sharp),
fillColor: Colors.green,
hintText: 'My Hint',
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 16.0,
fontWeight: FontWeight.w400,
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Colors.green,
),
// borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
contentPadding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 10,
),
border: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Colors.green,
),
// borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Colors.green,
),
// borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
),
),
),
);
}
}