google_map_marker 0.0.2 google_map_marker: ^0.0.2 copied to clipboard
Custom marker form google maps flutter
import 'dart:async';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:google_map_marker/google_map_marker.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final Completer<GoogleMapController> _controller =
Completer<GoogleMapController>();
static const CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(37.42796133580664, -122.085749655962),
zoom: 14.4746,
);
BitmapDescriptor? marker;
List<Marker> markers = [];
bool init = false;
@override
void initState() {
getMarker();
super.initState();
}
getMarker() async {
marker = await GoogleMapMarker.getMarker(
context, "assets/cube_transparent.png");
addMarker();
setState(() {
init = true;
});
}
addMarker() {
if(marker != null){
markers.add(
Marker(
markerId: const MarkerId('0'),
icon: marker!,
position: const LatLng(37.42796133580664, -122.085749655962)),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: init
? GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
markers: markers.toSet(),
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
)
: const Center(
child: CircularProgressIndicator(),
),
);
}
}