nc-photos/lib/web/google_gps_map.dart

49 lines
1.2 KiB
Dart
Raw Normal View History

2021-04-19 18:14:32 +02:00
// ignore: avoid_web_libraries_in_flutter
import 'dart:html';
import 'package:/nc_photos/mobile/ui_hack.dart' if (dart.library.html) 'dart:ui'
as ui;
import 'package:flutter/widgets.dart';
import 'package:tuple/tuple.dart';
2021-11-17 15:41:11 +01:00
class GoogleGpsMap extends StatefulWidget {
const GoogleGpsMap({
2021-07-23 22:05:57 +02:00
Key? key,
required this.center,
required this.zoom,
2021-04-19 18:14:32 +02:00
this.onTap,
}) : super(key: key);
@override
2021-11-17 15:41:11 +01:00
createState() => _GoogleGpsMapState();
2021-04-19 18:14:32 +02:00
final Tuple2<double, double> center;
final double zoom;
2021-07-23 22:05:57 +02:00
final void Function()? onTap;
2021-04-19 18:14:32 +02:00
}
2021-11-17 15:41:11 +01:00
class _GoogleGpsMapState extends State<GoogleGpsMap> {
2021-04-19 18:14:32 +02:00
@override
initState() {
super.initState();
final iframe = IFrameElement()
..src = "https://www.google.com/maps/embed/v1/place?key=$_apiKey"
"&q=${widget.center.item1},${widget.center.item2}"
"&zoom=${widget.zoom}"
..style.border = "none";
ui.platformViewRegistry.registerViewFactory(viewType, (viewId) => iframe);
}
@override
build(BuildContext context) {
return HtmlElementView(
viewType: viewType,
);
}
static const _apiKey = "";
String get viewType =>
2021-11-17 15:41:11 +01:00
"googleMapIframe(${widget.center.item1},${widget.center.item2})";
2021-04-19 18:14:32 +02:00
}