Stand 2024-12-09 - 3

This commit is contained in:
Jens Reinemuth 2024-12-09 14:04:43 +01:00
parent 6e727815c3
commit cab7615b08

View file

@ -1,11 +1,10 @@
import 'dart:async'; import 'dart:async';
import 'dart:collection';
import 'dart:io';
import 'dart:math' as Math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../../packages/ambito_theme/ambito_theme.dart';
class MapWidget extends StatefulWidget { class MapWidget extends StatefulWidget {
const MapWidget({super.key, required this.markers, required this.polygons}); const MapWidget({super.key, required this.markers, required this.polygons});
@ -20,8 +19,8 @@ class MapWidgetState extends State<MapWidget> {
final Completer<GoogleMapController> _controller = final Completer<GoogleMapController> _controller =
Completer<GoogleMapController>(); Completer<GoogleMapController>();
final con = GoogleMap bool _drawPolygon = false;
int _counter = 0;
static CameraPosition _initialPos = const CameraPosition( static CameraPosition _initialPos = const CameraPosition(
target: LatLng(0, 0), target: LatLng(0, 0),
@ -41,24 +40,55 @@ class MapWidgetState extends State<MapWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final AmbitoTheme theme = getTheme(context);
return ClipRRect( return ClipRRect(
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
height: 550, height: 600,
child: GoogleMap( child: Column(
mapToolbarEnabled: true, children: [
mapType: MapType.hybrid, Row(
markers: widget.markers ?? {}, children: [
polygons: widget.polygons ?? {}, Spacer(),
initialCameraPosition: _initialPos, IconButton(
onMapCreated: (GoogleMapController controller) { onPressed: () {
_controller.complete(controller); setState(() {
}, _drawPolygon = !_drawPolygon;
), });
), },
icon: Icon(
Icons.polyline_outlined,
color: (_drawPolygon
? theme.currentColorScheme.primary
: theme.currentColorScheme.outline),
))
],
),
Expanded(
child: GoogleMap(
onTap: (position) {
if (_drawPolygon == true) {
setState(() {
widget.markers?.add(Marker(
markerId: MarkerId('polygon_$_counter'),
position: position));
_counter++;
});
}
},
mapToolbarEnabled: true,
mapType: MapType.hybrid,
markers: widget.markers ?? {},
polygons: widget.polygons ?? {},
initialCameraPosition: _initialPos,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),
),
],
)),
); );
} }
} }