Skip to content

Add web support to place_tracker #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions place_tracker/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

# Flutter Web files
lib/generated_plugin_registrant.dart
7 changes: 7 additions & 0 deletions place_tracker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ Specify your API key in `AppDelegate.swift`:
}
```

### Web
Add your API key to `web/index.html` in the `<head>` tag:

```
<script src="https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY_HERE>"></script>
```

For additional help setting up the plugin, see the plugin's
[README](https://pub.dev/packages/google_maps_flutter)
page.
Expand Down
24 changes: 21 additions & 3 deletions place_tracker/lib/place_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MapConfiguration {
final List<Place> places;

final PlaceCategory selectedCategory;

const MapConfiguration({
@required this.places,
@required this.selectedCategory,
Expand Down Expand Up @@ -133,7 +134,21 @@ class PlaceMapState extends State<PlaceMap> {
});

// Zoom to fit the initially selected category.
await _zoomToFitPlaces(
_zoomToFitSelectedCategory();
}

@override
void didUpdateWidget(PlaceMap oldWidget) {
super.didUpdateWidget(oldWidget);
// Zoom to fit the selected category.
if (mounted) {
_zoomToFitSelectedCategory();
}
}

/// Applies zoom to fit the places of the selected category
void _zoomToFitSelectedCategory() {
_zoomToFitPlaces(
_getPlacesForCategory(
Provider.of<AppState>(context, listen: false).selectedCategory,
_markedPlaces.values.toList(),
Expand Down Expand Up @@ -414,11 +429,13 @@ class PlaceMapState extends State<PlaceMap> {
switch (category) {
case PlaceCategory.favorite:
return BitmapDescriptor.fromAssetImage(
createLocalImageConfiguration(context), 'assets/heart.png');
createLocalImageConfiguration(context, size: Size.square(32)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll miss those enormous blue flags. 😄

'assets/heart.png');
break;
case PlaceCategory.visited:
return BitmapDescriptor.fromAssetImage(
createLocalImageConfiguration(context), 'assets/visited.png');
createLocalImageConfiguration(context, size: Size.square(32)),
'assets/visited.png');
break;
case PlaceCategory.wantToGo:
default:
Expand All @@ -437,6 +454,7 @@ class _AddPlaceButtonBar extends StatelessWidget {

final VoidCallback onSavePressed;
final VoidCallback onCancelPressed;

const _AddPlaceButtonBar({
Key key,
@required this.visible,
Expand Down
95 changes: 71 additions & 24 deletions place_tracker/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.2"
version: "2.5.0-nullsafety"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.1.0-nullsafety.2"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
version: "1.2.0-nullsafety"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.0-nullsafety"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.13"
version: "1.15.0-nullsafety.2"
convert:
dependency: transitive
description:
Expand All @@ -57,6 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.2"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -70,7 +77,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.0-nullsafety"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -82,40 +89,73 @@ packages:
name: flutter_plugin_android_lifecycle
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.8"
version: "1.0.9"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
google_maps:
dependency: transitive
description:
name: google_maps
url: "https://pub.dartlang.org"
source: hosted
version: "3.4.5"
google_maps_flutter:
dependency: "direct main"
description:
name: google_maps_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.30"
version: "0.5.32"
google_maps_flutter_platform_interface:
dependency: transitive
description:
name: google_maps_flutter_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
google_maps_flutter_web:
dependency: "direct main"
description:
name: google_maps_flutter_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0+2"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+3"
js_wrapping:
dependency: transitive
description:
name: js_wrapping
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.8"
version: "0.12.10-nullsafety"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.2"
nested:
dependency: transitive
description:
Expand All @@ -129,14 +169,14 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety"
pedantic:
dependency: "direct dev"
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
version: "1.9.2"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -150,7 +190,14 @@ packages:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.2"
version: "4.3.2+2"
sanitize_html:
dependency: transitive
description:
name: sanitize_html
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -162,21 +209,21 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.5"
version: "1.10.0-nullsafety"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety"
stream_transform:
dependency: transitive
description:
Expand All @@ -190,42 +237,42 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.17"
version: "0.2.19-nullsafety"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0-nullsafety.2"
uuid:
dependency: "direct main"
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.2.2"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0-nullsafety.2"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
dart: ">=2.10.0-0.0.dev <2.10.0"
flutter: ">=1.16.3 <2.0.0"
3 changes: 2 additions & 1 deletion place_tracker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dependencies:
sdk: flutter

cupertino_icons: ^0.1.3
google_maps_flutter: ^0.5.27
google_maps_flutter: ^0.5.0
google_maps_flutter_web: ^0.1.0
provider: ^4.0.0
uuid: ^2.0.4

Expand Down
Binary file added place_tracker/web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added place_tracker/web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added place_tracker/web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions place_tracker/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="place_tracker">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png"/>

<!-- // Other stuff -->

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBEKgpAdjMVMv9IKX-BBsjzwgYMxfZonbw"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the key intended to be in here? We don't ship the app with the mobile API keys, which is why I'm asking. Even if this one isn't as "secret" as the mobile versions, it might be better to disassociate the app from any one account and update the README to tell people where to stick their own key.

Copy link
Contributor Author

@johnpryan johnpryan Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I would do that, but If we take it out, we can't deploy it to http://flutter.github.io/samples anymore.

We could consider writing this string as part of the samples index deployment (perhaps via an environment variable given to a GitHub action.) but the API key is still visible if you view the source of the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a section to the README for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I added some domain restrictions:

Screen Shot 2020-09-23 at 11 05 43 AM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted my previous comment because I just stated the obvious (again) xD


<title>place_tracker</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
Loading