-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.dart
137 lines (124 loc) · 3.2 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:widget_to_marker/widget_to_marker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Widget to Marker',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Widget to Marker'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Set<Marker> markers = {};
initMarkers() async {
markers = {};
markers.add(Marker(
markerId: const MarkerId("1"),
position: const LatLng(31.06976262630338, 31.23652808368206),
icon: await const CountWidget(count: 1).toBitmapDescriptor(
logicalSize: const Size(100, 100), imageSize: const Size(300, 300)),
));
markers.add(Marker(
markerId: const MarkerId("2"),
position: const LatLng(30.418868934059237, 31.22851464897394),
icon: await const MarkerWidget().toBitmapDescriptor(
logicalSize: const Size(20, 20), imageSize: const Size(200, 200)),
));
markers.add(Marker(
markerId: const MarkerId("3"),
position: const LatLng(30.01124477440843, 30.78459296375513),
icon: await const TextOnImage(
text: "Hello World",
).toBitmapDescriptor(
logicalSize: const Size(150, 150), imageSize: const Size(300, 400)),
));
setState(() {});
}
@override
void initState() {
initMarkers();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: GoogleMap(
initialCameraPosition: const CameraPosition(
target: LatLng(30.488774662306618, 31.032559163868427), zoom: 9),
markers: markers,
onTap: (s) {
print(s);
},
)));
}
}
class CountWidget extends StatelessWidget {
const CountWidget({super.key, required this.count});
final int count;
@override
Widget build(BuildContext context) {
return CircleAvatar(
child: Text('$count'),
);
}
}
class MarkerWidget extends StatelessWidget {
const MarkerWidget({
super.key,
});
@override
Widget build(BuildContext context) {
return const Image(
image: AssetImage(
"assets/marker2.png",
),
height: 150,
width: 150,
);
}
}
class TextOnImage extends StatelessWidget {
const TextOnImage({
super.key,
required this.text,
});
final String text;
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: [
const Image(
image: AssetImage(
"assets/marker.png",
),
height: 150,
width: 150,
),
Text(
text,
style: const TextStyle(color: Colors.black),
)
],
);
}
}