-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.dart
143 lines (130 loc) · 5.58 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
142
143
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_place_picker/flutter_place_picker.dart';
// Your api key storage.
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// Light Theme
final ThemeData lightTheme = ThemeData.light().copyWith(
// Background color of the FloatingCard
cardColor: Colors.white,
buttonTheme: const ButtonThemeData(
// Select here's button color
buttonColor: Colors.black,
textTheme: ButtonTextTheme.primary,
),
);
// Dark Theme
final ThemeData darkTheme = ThemeData.dark().copyWith(
// Background color of the FloatingCard
cardColor: Colors.grey,
buttonTheme: const ButtonThemeData(
// Select here's button color
buttonColor: Colors.yellow,
textTheme: ButtonTextTheme.primary,
),
);
MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Place Picker Demo',
theme: lightTheme,
darkTheme: darkTheme,
themeMode: ThemeMode.light,
home: const HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
PickResult? selectedPlace;
final LatLng kInitialPosition = const LatLng(-33.8567844, 151.213108);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Google Map Place Picker Demo"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Load Google Map"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return FlutterPlacePicker(
apiKey:
"YOUR KEY HERE", // Needed to display google maps and
initialPosition: kInitialPosition,
useCurrentLocation: true,
selectInitialPosition: true,
usePlaceDetailSearch: false,
region: 'gh',
strictBounds: true,
onPlacePicked: (result) {
selectedPlace = result;
print(result.geometry!.location.lat);
print(result.geometry!.location.lng);
print(result.placeId);
print(result.formattedAddress);
Navigator.of(context).pop();
setState(() {});
},
// serverUrl: "https://www.your-server.com/api/",
//automaticallyImplyAppBarLeading: false,
// selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) {
// print("state: $state, isSearchBarFocused: $isSearchBarFocused");
// return isSearchBarFocused
// ? Container()
// : FloatingCard(
// bottomPosition: 0.0, // MediaQuery.of(context) will cause rebuild. See MediaQuery document for the information.
// leftPosition: 0.0,
// rightPosition: 0.0,
// width: 500,
// borderRadius: BorderRadius.circular(12.0),
// child: state == SearchingState.Searching
// ? Center(child: CircularProgressIndicator())
// : RaisedButton(
// child: Text("Pick Here"),
// onPressed: () {
// // IMPORTANT: You MUST manage selectedPlace data yourself as using this build will not invoke onPlacePicker as
// // this will override default 'Select here' Button.
// print("do something with [selectedPlace] data");
// Navigator.of(context).pop();
// },
// ),
// );
// },
// pinBuilder: (context, state) {
// if (state == PinState.Idle) {
// return Icon(Icons.favorite_border);
// } else {
// return Icon(Icons.favorite);
// }
// },
);
},
),
);
},
),
selectedPlace == null
? Container()
: Text(selectedPlace!.formattedAddress ?? ""),
],
),
));
}
}