Skip to content

Commit 2236f12

Browse files
johnpryanditman
andauthored
Add web support to place_tracker (#550)
* enable web for place_tracker * add place_tracker symlink * add generated_plugin_registrant.dart * update google_maps_flutter_web to fix pins not showing * add place_tracker to peanut.yaml * upgrade place_tracker dep * use a 32 pixel square * Apply zoom to selected category when the PlaceMapState updates. This fixes a grey screen issue in web, after saving a place. * pub upgrade * run pub upgrade * use published versions of packages * remove lib/generated_plugin_registrant.dart * add newline * add web API key to README Co-authored-by: David Iglesias Teixeira <[email protected]>
1 parent 5e6eb5d commit 2236f12

12 files changed

+166
-28
lines changed

place_tracker/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@
6969
!**/ios/**/default.pbxuser
7070
!**/ios/**/default.perspectivev3
7171
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
72+
73+
# Flutter Web files
74+
lib/generated_plugin_registrant.dart

place_tracker/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ Specify your API key in `AppDelegate.swift`:
6161
}
6262
```
6363

64+
### Web
65+
Add your API key to `web/index.html` in the `<head>` tag:
66+
67+
```
68+
<script src="https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY_HERE>"></script>
69+
```
70+
6471
For additional help setting up the plugin, see the plugin's
6572
[README](https://pub.dev/packages/google_maps_flutter)
6673
page.

place_tracker/lib/place_map.dart

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class MapConfiguration {
1515
final List<Place> places;
1616

1717
final PlaceCategory selectedCategory;
18+
1819
const MapConfiguration({
1920
@required this.places,
2021
@required this.selectedCategory,
@@ -133,7 +134,21 @@ class PlaceMapState extends State<PlaceMap> {
133134
});
134135

135136
// Zoom to fit the initially selected category.
136-
await _zoomToFitPlaces(
137+
_zoomToFitSelectedCategory();
138+
}
139+
140+
@override
141+
void didUpdateWidget(PlaceMap oldWidget) {
142+
super.didUpdateWidget(oldWidget);
143+
// Zoom to fit the selected category.
144+
if (mounted) {
145+
_zoomToFitSelectedCategory();
146+
}
147+
}
148+
149+
/// Applies zoom to fit the places of the selected category
150+
void _zoomToFitSelectedCategory() {
151+
_zoomToFitPlaces(
137152
_getPlacesForCategory(
138153
Provider.of<AppState>(context, listen: false).selectedCategory,
139154
_markedPlaces.values.toList(),
@@ -414,11 +429,13 @@ class PlaceMapState extends State<PlaceMap> {
414429
switch (category) {
415430
case PlaceCategory.favorite:
416431
return BitmapDescriptor.fromAssetImage(
417-
createLocalImageConfiguration(context), 'assets/heart.png');
432+
createLocalImageConfiguration(context, size: Size.square(32)),
433+
'assets/heart.png');
418434
break;
419435
case PlaceCategory.visited:
420436
return BitmapDescriptor.fromAssetImage(
421-
createLocalImageConfiguration(context), 'assets/visited.png');
437+
createLocalImageConfiguration(context, size: Size.square(32)),
438+
'assets/visited.png');
422439
break;
423440
case PlaceCategory.wantToGo:
424441
default:
@@ -437,6 +454,7 @@ class _AddPlaceButtonBar extends StatelessWidget {
437454

438455
final VoidCallback onSavePressed;
439456
final VoidCallback onCancelPressed;
457+
440458
const _AddPlaceButtonBar({
441459
Key key,
442460
@required this.visible,

place_tracker/pubspec.lock

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,42 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.4.2"
10+
version: "2.5.0-nullsafety"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.0.0"
17+
version: "2.1.0-nullsafety"
1818
characters:
1919
dependency: transitive
2020
description:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.0.0"
24+
version: "1.1.0-nullsafety.2"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.1.3"
31+
version: "1.2.0-nullsafety"
3232
clock:
3333
dependency: transitive
3434
description:
3535
name: clock
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "1.0.1"
38+
version: "1.1.0-nullsafety"
3939
collection:
4040
dependency: transitive
4141
description:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.14.13"
45+
version: "1.15.0-nullsafety.2"
4646
convert:
4747
dependency: transitive
4848
description:
@@ -57,6 +57,13 @@ packages:
5757
url: "https://pub.dartlang.org"
5858
source: hosted
5959
version: "2.1.5"
60+
csslib:
61+
dependency: transitive
62+
description:
63+
name: csslib
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "0.16.2"
6067
cupertino_icons:
6168
dependency: "direct main"
6269
description:
@@ -70,7 +77,7 @@ packages:
7077
name: fake_async
7178
url: "https://pub.dartlang.org"
7279
source: hosted
73-
version: "1.1.0"
80+
version: "1.1.0-nullsafety"
7481
flutter:
7582
dependency: "direct main"
7683
description: flutter
@@ -82,40 +89,73 @@ packages:
8289
name: flutter_plugin_android_lifecycle
8390
url: "https://pub.dartlang.org"
8491
source: hosted
85-
version: "1.0.8"
92+
version: "1.0.9"
8693
flutter_test:
8794
dependency: "direct dev"
8895
description: flutter
8996
source: sdk
9097
version: "0.0.0"
98+
flutter_web_plugins:
99+
dependency: transitive
100+
description: flutter
101+
source: sdk
102+
version: "0.0.0"
103+
google_maps:
104+
dependency: transitive
105+
description:
106+
name: google_maps
107+
url: "https://pub.dartlang.org"
108+
source: hosted
109+
version: "3.4.5"
91110
google_maps_flutter:
92111
dependency: "direct main"
93112
description:
94113
name: google_maps_flutter
95114
url: "https://pub.dartlang.org"
96115
source: hosted
97-
version: "0.5.30"
116+
version: "0.5.32"
98117
google_maps_flutter_platform_interface:
99118
dependency: transitive
100119
description:
101120
name: google_maps_flutter_platform_interface
102121
url: "https://pub.dartlang.org"
103122
source: hosted
104123
version: "1.0.4"
124+
google_maps_flutter_web:
125+
dependency: "direct main"
126+
description:
127+
name: google_maps_flutter_web
128+
url: "https://pub.dartlang.org"
129+
source: hosted
130+
version: "0.1.0+2"
131+
html:
132+
dependency: transitive
133+
description:
134+
name: html
135+
url: "https://pub.dartlang.org"
136+
source: hosted
137+
version: "0.14.0+3"
138+
js_wrapping:
139+
dependency: transitive
140+
description:
141+
name: js_wrapping
142+
url: "https://pub.dartlang.org"
143+
source: hosted
144+
version: "0.5.0"
105145
matcher:
106146
dependency: transitive
107147
description:
108148
name: matcher
109149
url: "https://pub.dartlang.org"
110150
source: hosted
111-
version: "0.12.8"
151+
version: "0.12.10-nullsafety"
112152
meta:
113153
dependency: transitive
114154
description:
115155
name: meta
116156
url: "https://pub.dartlang.org"
117157
source: hosted
118-
version: "1.1.8"
158+
version: "1.3.0-nullsafety.2"
119159
nested:
120160
dependency: transitive
121161
description:
@@ -129,14 +169,14 @@ packages:
129169
name: path
130170
url: "https://pub.dartlang.org"
131171
source: hosted
132-
version: "1.7.0"
172+
version: "1.8.0-nullsafety"
133173
pedantic:
134174
dependency: "direct dev"
135175
description:
136176
name: pedantic
137177
url: "https://pub.dartlang.org"
138178
source: hosted
139-
version: "1.9.0"
179+
version: "1.9.2"
140180
plugin_platform_interface:
141181
dependency: transitive
142182
description:
@@ -150,7 +190,14 @@ packages:
150190
name: provider
151191
url: "https://pub.dartlang.org"
152192
source: hosted
153-
version: "4.3.2"
193+
version: "4.3.2+2"
194+
sanitize_html:
195+
dependency: transitive
196+
description:
197+
name: sanitize_html
198+
url: "https://pub.dartlang.org"
199+
source: hosted
200+
version: "1.3.0"
154201
sky_engine:
155202
dependency: transitive
156203
description: flutter
@@ -162,21 +209,21 @@ packages:
162209
name: source_span
163210
url: "https://pub.dartlang.org"
164211
source: hosted
165-
version: "1.7.0"
212+
version: "1.8.0-nullsafety"
166213
stack_trace:
167214
dependency: transitive
168215
description:
169216
name: stack_trace
170217
url: "https://pub.dartlang.org"
171218
source: hosted
172-
version: "1.9.5"
219+
version: "1.10.0-nullsafety"
173220
stream_channel:
174221
dependency: transitive
175222
description:
176223
name: stream_channel
177224
url: "https://pub.dartlang.org"
178225
source: hosted
179-
version: "2.0.0"
226+
version: "2.1.0-nullsafety"
180227
stream_transform:
181228
dependency: transitive
182229
description:
@@ -190,42 +237,42 @@ packages:
190237
name: string_scanner
191238
url: "https://pub.dartlang.org"
192239
source: hosted
193-
version: "1.0.5"
240+
version: "1.1.0-nullsafety"
194241
term_glyph:
195242
dependency: transitive
196243
description:
197244
name: term_glyph
198245
url: "https://pub.dartlang.org"
199246
source: hosted
200-
version: "1.1.0"
247+
version: "1.2.0-nullsafety"
201248
test_api:
202249
dependency: transitive
203250
description:
204251
name: test_api
205252
url: "https://pub.dartlang.org"
206253
source: hosted
207-
version: "0.2.17"
254+
version: "0.2.19-nullsafety"
208255
typed_data:
209256
dependency: transitive
210257
description:
211258
name: typed_data
212259
url: "https://pub.dartlang.org"
213260
source: hosted
214-
version: "1.2.0"
261+
version: "1.3.0-nullsafety.2"
215262
uuid:
216263
dependency: "direct main"
217264
description:
218265
name: uuid
219266
url: "https://pub.dartlang.org"
220267
source: hosted
221-
version: "2.2.0"
268+
version: "2.2.2"
222269
vector_math:
223270
dependency: transitive
224271
description:
225272
name: vector_math
226273
url: "https://pub.dartlang.org"
227274
source: hosted
228-
version: "2.0.8"
275+
version: "2.1.0-nullsafety.2"
229276
sdks:
230-
dart: ">=2.9.0-14.0.dev <3.0.0"
277+
dart: ">=2.10.0-0.0.dev <2.10.0"
231278
flutter: ">=1.16.3 <2.0.0"

place_tracker/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ dependencies:
1111
sdk: flutter
1212

1313
cupertino_icons: ^0.1.3
14-
google_maps_flutter: ^0.5.27
14+
google_maps_flutter: ^0.5.0
15+
google_maps_flutter_web: ^0.1.0
1516
provider: ^4.0.0
1617
uuid: ^2.0.4
1718

place_tracker/web/favicon.png

917 Bytes
Loading

place_tracker/web/icons/Icon-192.png

5.17 KB
Loading

place_tracker/web/icons/Icon-512.png

8.06 KB
Loading

place_tracker/web/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
6+
<meta name="description" content="A new Flutter project.">
7+
8+
<!-- iOS meta tags & icons -->
9+
<meta name="apple-mobile-web-app-capable" content="yes">
10+
<meta name="apple-mobile-web-app-status-bar-style" content="black">
11+
<meta name="apple-mobile-web-app-title" content="place_tracker">
12+
<link rel="apple-touch-icon" href="icons/Icon-192.png">
13+
14+
<!-- Favicon -->
15+
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
16+
17+
<!-- // Other stuff -->
18+
19+
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBEKgpAdjMVMv9IKX-BBsjzwgYMxfZonbw"></script>
20+
21+
<title>place_tracker</title>
22+
<link rel="manifest" href="manifest.json">
23+
</head>
24+
<body>
25+
<!-- This script installs service_worker.js to provide PWA functionality to
26+
application. For more information, see:
27+
https://developers.google.com/web/fundamentals/primers/service-workers -->
28+
<script>
29+
if ('serviceWorker' in navigator) {
30+
window.addEventListener('load', function () {
31+
navigator.serviceWorker.register('flutter_service_worker.js');
32+
});
33+
}
34+
</script>
35+
<script src="main.dart.js" type="application/javascript"></script>
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)