diff --git a/lib/src/widgets/map/map_widget.dart b/lib/src/widgets/map/map_widget.dart index 377ad58..251358b 100644 --- a/lib/src/widgets/map/map_widget.dart +++ b/lib/src/widgets/map/map_widget.dart @@ -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 { final Completer _controller = Completer(); - 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 { @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); + }, + ), + ), + ], + )), ); } - - }