cached_custom_marker 0.0.2+1 copy "cached_custom_marker: ^0.0.2+1" to clipboard
cached_custom_marker: ^0.0.2+1 copied to clipboard

discontinued

Cached Custom Marker is a Flutter package designed for optimizing map-based applications by efficiently managing custom markers. It automates the downloading, caching, and conversion of images into Bi [...]

example/lib/main.dart

import 'package:cached_custom_marker/cached_custom_marker.dart';
import 'package:flutter/material.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 HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Cached Custom Marker Demo'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            Navigator.of(context).push(
              MaterialPageRoute(
                builder: (context) => const GoogleMapView(),
              ),
            );
          },
          child: const Text('Go to Google Map View'),
        ),
      ),
    );
  }
}

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

  @override
  State<GoogleMapView> createState() => _GoogleMapViewState();
}

class _GoogleMapViewState extends State<GoogleMapView> {
  Set<Marker> markers = {};
  late CachedCustomMarker _cachedCustomMarker;

  @override
  void initState() {
    _cachedCustomMarker = CachedCustomMarker();
    _initMarkers();
    super.initState();
  }

  void _initMarkers() async {
    late Marker networkMarker;
    late Marker bytesMarker;
    final futures = await Future.wait([
      _cachedCustomMarker.fromNetwork(
          url: 'https://cdn-icons-png.flaticon.com/512/5193/5193688.png',
          size: const Size(60, 60)),
      _cachedCustomMarker.fromWidget(
        widget: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(50),
          ),
          child: const Icon(
            Icons.location_on,
            color: Colors.red,
            size: 50,
          ),
        ),
        cacheKey: 'widget_marker',
        logicalSize: const Size(250, 250),
        imageSize: const Size(100, 100),
      )
    ]);
    networkMarker = Marker(
        markerId: const MarkerId('network_marker_id'),
        position: const LatLng(37.77483, -122.41942),
        icon: futures[0]);

    bytesMarker = Marker(
        markerId: const MarkerId('bytes_marker_id'),
        position: const LatLng(37.734921595128405, -122.43419039994477),
        icon: futures[1]);
    setState(() {
      markers.addAll([networkMarker, bytesMarker]);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Cached Custom Marker Demo'),
      ),
      body: GoogleMap(
        initialCameraPosition: const CameraPosition(
          target: LatLng(37.77483, -122.41942),
          zoom: 12,
        ),
        markers: markers,
      ),
    );
  }
}
4
likes
0
pub points
56%
popularity

Publisher

unverified uploader

Cached Custom Marker is a Flutter package designed for optimizing map-based applications by efficiently managing custom markers. It automates the downloading, caching, and conversion of images into BitmapDescriptor objects for Google Maps, significantly reducing load times and network requests. With features like custom marker sizing and effective cache management, it's an essential tool for developers aiming to enhance user experience in their Flutter map applications.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_cache_manager, google_maps_flutter

More

Packages that depend on cached_custom_marker