Skip to content

Commit

Permalink
Draw polygone on map & solve some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Usaid-Dev committed Mar 16, 2023
1 parent f2e7703 commit deeebd2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/custom_marker_info_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CustomMarkerInfoWindow extends StatefulWidget {
}

class _CustomMarkerInfoWindowState extends State<CustomMarkerInfoWindow> {
CustomInfoWindowController _customInfoWindowController =
final CustomInfoWindowController _customInfoWindowController =
CustomInfoWindowController();

final List<Marker> _markers = <Marker>[];
Expand Down
2 changes: 1 addition & 1 deletion lib/custom_marker_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CustomMarkerScreen extends StatefulWidget {
const CustomMarkerScreen({Key? key}) : super(key: key);

@override
_CustomMarkerScreenState createState() => _CustomMarkerScreenState();
State<CustomMarkerScreen> createState() => _CustomMarkerScreenState();
}

class _CustomMarkerScreenState extends State<CustomMarkerScreen> {
Expand Down
2 changes: 1 addition & 1 deletion lib/google_places_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GooglePlacesApiScreen extends StatefulWidget {
}

class _GooglePlacesApiScreenState extends State<GooglePlacesApiScreen> {
TextEditingController _controller = TextEditingController();
final TextEditingController _controller = TextEditingController();

var uuid = const Uuid();

Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'custom_marker_info_window.dart';
import 'package:google_map/polygone_screen.dart';

void main() {
runApp(const MyApp());
Expand All @@ -16,7 +16,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const CustomMarkerInfoWindow(),
home: const PolygoneScreen(),
);
}
}
67 changes: 67 additions & 0 deletions lib/polygone_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'dart:async';
import 'dart:collection';

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class PolygoneScreen extends StatefulWidget {
const PolygoneScreen({super.key});

@override
State<PolygoneScreen> createState() => _PolygoneScreenState();
}

class _PolygoneScreenState extends State<PolygoneScreen> {
final Completer<GoogleMapController> _controller = Completer();

static const CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(33.654235, 73.073000),
zoom: 14,
);
final Set<Marker> _markers = {};
final Set<Polygon> _polygone = HashSet<Polygon>();

List<LatLng> points = [
const LatLng(33.654235, 73.073000),
const LatLng(33.647326, 72.820175),
const LatLng(33.689531, 72.763160),
const LatLng(34.131452, 72.662334),
const LatLng(33.654235, 73.073000),
];

void _setPolygone() {
_polygone.add(Polygon(
polygonId: const PolygonId('1'),
points: points,
strokeColor: Colors.deepOrange,
strokeWidth: 5,
fillColor: Colors.deepOrange.withOpacity(0.1),
geodesic: true));
}

@override
void initState() {
super.initState();
_setPolygone();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Polygone'),
),
body: GoogleMap(
mapType: MapType.normal,
initialCameraPosition: _kGooglePlex,
myLocationButtonEnabled: true,
myLocationEnabled: false,
markers: _markers,
polygons: _polygone,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),
);
}
}

0 comments on commit deeebd2

Please sign in to comment.