Skip to content

Commit 67fac6c

Browse files
authored
Merge pull request #10 from rithik-dev/8-platform-exception
Fixes #8
2 parents 085bc1e + 0752a58 commit 67fac6c

File tree

9 files changed

+469
-583
lines changed

9 files changed

+469
-583
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
## [1.0.5] - 29/09/2022
2-
1+
## [1.0.5] - 25/10/2022
2+
3+
* BREAKING: `MarkerIconInfo` inputs are now non-nullable
4+
* BREAKING: Added properties `onTapMarker`, `onTapInfoWindow`, `infoWindowTitle` and `isVisible` to `MarkerIconInfo`, and removed corresponding params for source, destination, driver from `GoogleMapsWidget`
5+
* Changed internal implementation of the widget
6+
* Added `layoutDirection` property
7+
* Added `onPolylineUpdate` callback
8+
* Exposed state class to allow updating source/destination lat lng, or interacting with google maps con directly
39
* Updated a dependency to the latest release
10+
* Updated example app
11+
* Updated README.md
412

513
## [1.0.4] - 15/06/2022
614

README.md

Lines changed: 121 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,34 @@ GoogleMapsWidget(
125125
),
126126
```
127127

128+
One can create a controller and interact with the google maps controller, or update the source and destination LatLng's.
129+
```dart
130+
// can create a controller, and call methods to update source loc,
131+
// destination loc, interact with the google maps controller to
132+
// show/hide markers programmatically etc.
133+
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();
134+
```
135+
Pass this controller to the `key` param in `GoogleMapsWidget` widget, and then
136+
```dart
137+
138+
// call like this to update source or destination, this will also rebuild the route.
139+
mapsWidgetController.currentState!.setSourceLatLng(
140+
LatLng(
141+
40.484000837597925 * (Random().nextDouble()),
142+
-3.369978368282318,
143+
),
144+
);
145+
146+
// or, can interact with the google maps controller directly to focus on a marker etc..
147+
148+
final googleMapsCon = await mapsWidgetController.currentState!.getGoogleMapsController();
149+
googleMapsCon.showMarkerInfoWindow(MarkerIconInfo.sourceMarkerId);
150+
```
151+
128152
Sample Usage
129153
```dart
154+
import 'dart:math';
155+
130156
import 'package:flutter/material.dart';
131157
import 'package:google_maps_widget/google_maps_widget.dart';
132158
@@ -135,59 +161,113 @@ void main() {
135161
}
136162
137163
class MyApp extends StatelessWidget {
164+
// can create a controller, and call methods to update source loc,
165+
// destination loc, interact with the google maps controller to
166+
// show/hide markers programmatically etc.
167+
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();
168+
138169
@override
139170
Widget build(BuildContext context) {
140171
return MaterialApp(
141172
home: SafeArea(
142173
child: Scaffold(
143-
body: GoogleMapsWidget(
144-
apiKey: "YOUR KEY HERE",
145-
sourceLatLng: LatLng(40.484000837597925, -3.369978368282318),
146-
destinationLatLng: LatLng(40.48017307700204, -3.3618026599287987),
147-
148-
///////////////////////////////////////////////////////
149-
////////////// OPTIONAL PARAMETERS //////////////
150-
///////////////////////////////////////////////////////
151-
152-
routeWidth: 2,
153-
sourceMarkerIconInfo: MarkerIconInfo(
154-
assetPath: "assets/images/house-marker-icon.png",
155-
),
156-
destinationMarkerIconInfo: MarkerIconInfo(
157-
assetPath: "assets/images/restaurant-marker-icon.png",
158-
),
159-
driverMarkerIconInfo: MarkerIconInfo(
160-
assetPath: "assets/images/driver-marker-icon.png",
161-
assetMarkerSize: Size.square(125),
162-
rotation: 15.0,
163-
164-
// ... and more
165-
),
166-
// mock stream
167-
driverCoordinatesStream: Stream.periodic(
168-
Duration(milliseconds: 500),
169-
(i) => LatLng(
170-
40.47747872288886 + i / 10000,
171-
-3.368043154478073 - i / 10000,
174+
body: Column(
175+
children: [
176+
Expanded(
177+
child: GoogleMapsWidget(
178+
apiKey: "YOUR GOOGLE MAPS API KEY HERE",
179+
key: mapsWidgetController,
180+
sourceLatLng: LatLng(
181+
40.484000837597925,
182+
-3.369978368282318,
183+
),
184+
destinationLatLng: LatLng(
185+
40.48017307700204,
186+
-3.3618026599287987,
187+
),
188+
189+
///////////////////////////////////////////////////////
190+
////////////// OPTIONAL PARAMETERS //////////////
191+
///////////////////////////////////////////////////////
192+
193+
routeWidth: 2,
194+
sourceMarkerIconInfo: MarkerIconInfo(
195+
infoWindowTitle: "This is source name",
196+
onTapInfoWindow: (_) {
197+
print("Tapped on source info window");
198+
},
199+
assetPath: "assets/images/house-marker-icon.png",
200+
),
201+
destinationMarkerIconInfo: MarkerIconInfo(
202+
assetPath: "assets/images/restaurant-marker-icon.png",
203+
),
204+
driverMarkerIconInfo: MarkerIconInfo(
205+
infoWindowTitle: "Alex",
206+
assetPath: "assets/images/driver-marker-icon.png",
207+
onTapMarker: (currentLocation) {
208+
print("Driver is currently at $currentLocation");
209+
},
210+
assetMarkerSize: Size.square(125),
211+
rotation: 90,
212+
),
213+
updatePolylinesOnDriverLocUpdate: true,
214+
onPolylineUpdate: (_) {
215+
print("Polyline updated");
216+
},
217+
// mock stream
218+
driverCoordinatesStream: Stream.periodic(
219+
Duration(milliseconds: 500),
220+
(i) => LatLng(
221+
40.47747872288886 + i / 10000,
222+
-3.368043154478073 - i / 10000,
223+
),
224+
),
225+
totalTimeCallback: (time) => print(time),
226+
totalDistanceCallback: (distance) => print(distance),
227+
),
228+
),
229+
// demonstrates how to interact with the controller
230+
Padding(
231+
padding: const EdgeInsets.all(10),
232+
child: Row(
233+
children: [
234+
Expanded(
235+
child: ElevatedButton(
236+
onPressed: () {
237+
mapsWidgetController.currentState!.setSourceLatLng(
238+
LatLng(
239+
40.484000837597925 * (Random().nextDouble()),
240+
-3.369978368282318,
241+
),
242+
);
243+
},
244+
child: Text('Update source'),
245+
),
246+
),
247+
const SizedBox(width: 10),
248+
Expanded(
249+
child: ElevatedButton(
250+
onPressed: () async {
251+
final googleMapsCon = await mapsWidgetController
252+
.currentState!
253+
.getGoogleMapsController();
254+
googleMapsCon.showMarkerInfoWindow(
255+
MarkerIconInfo.sourceMarkerId,
256+
);
257+
},
258+
child: Text('Show source info'),
259+
),
260+
),
261+
],
262+
),
172263
),
173-
),
174-
updatePolylinesOnDriverLocUpdate: true,
175-
sourceName: "This is source name",
176-
driverName: "Alex",
177-
onTapDriverMarker: (currentLocation) {
178-
print("Driver is currently at $currentLocation");
179-
},
180-
totalTimeCallback: (time) => print(time),
181-
totalDistanceCallback: (distance) => print(distance),
182-
183-
/// and a lot more...
264+
],
184265
),
185266
),
186267
),
187268
);
188269
}
189270
}
190-
191271
```
192272

193273
See the [`example`](https://github.com/rithik-dev/google_maps_widget/blob/master/example) directory for a complete sample app.

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<meta-data
88
android:name="com.google.android.geo.API_KEY"
9-
android:value="YOUR KEY HERE" />
9+
android:value="YOUR GOOGLE MAPS API KEY HERE" />
1010

1111
<activity
1212
android:name=".MainActivity"

example/lib/main.dart

Lines changed: 95 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:math';
2+
13
import 'package:flutter/material.dart';
24
import 'package:google_maps_widget/google_maps_widget.dart';
35

@@ -6,48 +8,107 @@ void main() {
68
}
79

810
class MyApp extends StatelessWidget {
11+
// can create a controller, and call methods to update source loc,
12+
// destination loc, interact with the google maps controller to
13+
// show/hide markers programmatically etc.
14+
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();
15+
916
@override
1017
Widget build(BuildContext context) {
1118
return MaterialApp(
1219
home: SafeArea(
1320
child: Scaffold(
14-
body: GoogleMapsWidget(
15-
apiKey: "YOUR KEY HERE",
16-
sourceLatLng: LatLng(40.484000837597925, -3.369978368282318),
17-
destinationLatLng: LatLng(40.48017307700204, -3.3618026599287987),
21+
body: Column(
22+
children: [
23+
Expanded(
24+
child: GoogleMapsWidget(
25+
apiKey: "YOUR GOOGLE MAPS API KEY HERE",
26+
key: mapsWidgetController,
27+
sourceLatLng: LatLng(
28+
40.484000837597925,
29+
-3.369978368282318,
30+
),
31+
destinationLatLng: LatLng(
32+
40.48017307700204,
33+
-3.3618026599287987,
34+
),
1835

19-
///////////////////////////////////////////////////////
20-
////////////// OPTIONAL PARAMETERS //////////////
21-
///////////////////////////////////////////////////////
36+
///////////////////////////////////////////////////////
37+
////////////// OPTIONAL PARAMETERS //////////////
38+
///////////////////////////////////////////////////////
2239
23-
routeWidth: 2,
24-
sourceMarkerIconInfo: MarkerIconInfo(
25-
assetPath: "assets/images/house-marker-icon.png",
26-
),
27-
destinationMarkerIconInfo: MarkerIconInfo(
28-
assetPath: "assets/images/restaurant-marker-icon.png",
29-
),
30-
driverMarkerIconInfo: MarkerIconInfo(
31-
assetPath: "assets/images/driver-marker-icon.png",
32-
assetMarkerSize: Size.square(125),
33-
rotation: 90,
34-
),
35-
updatePolylinesOnDriverLocUpdate: true,
36-
// mock stream
37-
driverCoordinatesStream: Stream.periodic(
38-
Duration(milliseconds: 500),
39-
(i) => LatLng(
40-
40.47747872288886 + i / 10000,
41-
-3.368043154478073 - i / 10000,
40+
routeWidth: 2,
41+
sourceMarkerIconInfo: MarkerIconInfo(
42+
infoWindowTitle: "This is source name",
43+
onTapInfoWindow: (_) {
44+
print("Tapped on source info window");
45+
},
46+
assetPath: "assets/images/house-marker-icon.png",
47+
),
48+
destinationMarkerIconInfo: MarkerIconInfo(
49+
assetPath: "assets/images/restaurant-marker-icon.png",
50+
),
51+
driverMarkerIconInfo: MarkerIconInfo(
52+
infoWindowTitle: "Alex",
53+
assetPath: "assets/images/driver-marker-icon.png",
54+
onTapMarker: (currentLocation) {
55+
print("Driver is currently at $currentLocation");
56+
},
57+
assetMarkerSize: Size.square(125),
58+
rotation: 90,
59+
),
60+
onPolylineUpdate: (p) {
61+
print("Polyline updated: ${p.points}");
62+
},
63+
updatePolylinesOnDriverLocUpdate: true,
64+
// mock stream
65+
driverCoordinatesStream: Stream.periodic(
66+
Duration(milliseconds: 500),
67+
(i) => LatLng(
68+
40.47747872288886 + i / 10000,
69+
-3.368043154478073 - i / 10000,
70+
),
71+
),
72+
totalTimeCallback: (time) => print(time),
73+
totalDistanceCallback: (distance) => print(distance),
74+
),
75+
),
76+
// demonstrates how to interact with the controller
77+
Padding(
78+
padding: const EdgeInsets.all(10),
79+
child: Row(
80+
children: [
81+
Expanded(
82+
child: ElevatedButton(
83+
onPressed: () {
84+
mapsWidgetController.currentState!.setSourceLatLng(
85+
LatLng(
86+
40.484000837597925 * (Random().nextDouble()),
87+
-3.369978368282318,
88+
),
89+
);
90+
},
91+
child: Text('Update source'),
92+
),
93+
),
94+
const SizedBox(width: 10),
95+
Expanded(
96+
child: ElevatedButton(
97+
onPressed: () async {
98+
final googleMapsCon = await mapsWidgetController
99+
.currentState!
100+
.getGoogleMapsController();
101+
googleMapsCon.showMarkerInfoWindow(
102+
MarkerIconInfo.sourceMarkerId,
103+
);
104+
},
105+
child: Text('Show source info'),
106+
),
107+
),
108+
],
109+
),
42110
),
43-
),
44-
sourceName: "This is source name",
45-
driverName: "Alex",
46-
onTapDriverMarker: (currentLocation) {
47-
print("Driver is currently at $currentLocation");
48-
},
49-
totalTimeCallback: (time) => print(time),
50-
totalDistanceCallback: (distance) => print(distance),
111+
],
51112
),
52113
),
53114
),

0 commit comments

Comments
 (0)