label_marker 1.0.1 copy "label_marker: ^1.0.1" to clipboard
label_marker: ^1.0.1 copied to clipboard

A package to create and use Google Maps marker with label text; the easiest and most efficient way.

example/example.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Label Marker example',
      home: MyHomePage(title: 'Label Marker Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Set<Marker> markers = {};
  GoogleMapController? controller;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: GoogleMap(
        initialCameraPosition: const CameraPosition(
          target: LatLng(0, 0),
          zoom: 1,
        ),
        markers: markers,
        onMapCreated: ((mapController) {
          setState(() {
            controller = mapController;
          });
        }),
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add),
        onPressed: (() {
          final lat = (Random().nextDouble() * 180) - 90;
          final lng = (Random().nextDouble() * 360) - 180;
          final title = "title${Random().nextInt(1000)}";
          markers
              .addLabelMarker(LabelMarker(
            label: title,
            markerId: MarkerId(title),
            position: LatLng(lat, lng),
            backgroundColor: Colors.green,
          ))
              .then(
            (value) {
              setState(() {});
            },
          );
        }),
      ),
    );
  }
}
75
likes
140
pub points
96%
popularity

Publisher

verified publisherscaria.dev

A package to create and use Google Maps marker with label text; the easiest and most efficient way.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, google_maps_flutter

More

Packages that depend on label_marker