google_map_marker 0.0.3 copy "google_map_marker: ^0.0.3" to clipboard
google_map_marker: ^0.0.3 copied to clipboard

A new Flutter package to make custom google map marker for google maps from an asset image

example/lib/main.dart

import 'dart:async';

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(),
            ),
    );
  }
}
1
likes
150
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

A new Flutter package to make custom google map marker for google maps from an asset image

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, google_maps_flutter

More

Packages that depend on google_map_marker