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:collection';
import 'dart:io';
import 'dart:math' as Math;
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../../packages/ambito_theme/ambito_theme.dart';
class MapWidget extends StatefulWidget {
const MapWidget({super.key, required this.markers, required this.polygons});
@ -20,8 +19,8 @@ class MapWidgetState extends State<MapWidget> {
final Completer<GoogleMapController> _controller =
Completer<GoogleMapController>();
final con = GoogleMap
bool _drawPolygon = false;
int _counter = 0;
static CameraPosition _initialPos = const CameraPosition(
target: LatLng(0, 0),
@ -41,24 +40,55 @@ class MapWidgetState extends State<MapWidget> {
@override
Widget build(BuildContext context) {
final AmbitoTheme theme = getTheme(context);
return ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: SizedBox(
width: double.infinity,
height: 550,
child: GoogleMap(
mapToolbarEnabled: true,
mapType: MapType.hybrid,
markers: widget.markers ?? {},
polygons: widget.polygons ?? {},
initialCameraPosition: _initialPos,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),
),
width: double.infinity,
height: 600,
child: Column(
children: [
Row(
children: [
Spacer(),
IconButton(
onPressed: () {
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);
},
),
),
],
)),
);
}
}