flutter_map_tile_switcher 0.0.2 copy "flutter_map_tile_switcher: ^0.0.2" to clipboard
flutter_map_tile_switcher: ^0.0.2 copied to clipboard

A flutter_map plugin for easy switching between map tile providers (OpenStreetMap, Google Maps, Satellite) with built-in caching and automatic dark mode support.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_tile_switcher/flutter_map_tile_switcher.dart';
import 'package:latlong2/latlong.dart';

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Tile Switcher Example',
      theme: ThemeData.light(useMaterial3: true),
      darkTheme: ThemeData.dark(useMaterial3: true),
      themeMode: ThemeMode.system,
      home: const MapScreen(),
    );
  }
}

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

  @override
  State<MapScreen> createState() => _MapScreenState();
}

class _MapScreenState extends State<MapScreen> {
  MapTileType _currentType = MapTileType.osm;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Tile Switcher Example'),
        actions: [
          // Map type selector
          PopupMenuButton<MapTileType>(
            icon: const Icon(Icons.layers),
            onSelected: (type) => setState(() => _currentType = type),
            itemBuilder: (context) => [
              const PopupMenuItem(
                value: MapTileType.osm,
                child: Text('OpenStreetMap'),
              ),
              const PopupMenuItem(
                value: MapTileType.google,
                child: Text('Google Maps'),
              ),
              const PopupMenuItem(
                value: MapTileType.satellite,
                child: Text('Satellite'),
              ),
            ],
          ),
          // Clear cache button
          IconButton(
            icon: const Icon(Icons.delete_outline),
            tooltip: 'Clear tile cache',
            onPressed: () async {
              await TileCacheManager.clearCache();
              if (context.mounted) {
                ScaffoldMessenger.of(context).showSnackBar(
                  const SnackBar(content: Text('Tile cache cleared')),
                );
              }
            },
          ),
        ],
      ),
      body: FlutterMap(
        options: MapOptions(
          initialCenter: const LatLng(37.9838, 23.7275), // Athens, Greece
          initialZoom: 13,
        ),
        children: [
          MapTileLayer(mapType: _currentType),
        ],
      ),
    );
  }
}
0
likes
160
points
36
downloads

Documentation

API reference

Publisher

verified publisherorestislef.gr

Weekly Downloads

A flutter_map plugin for easy switching between map tile providers (OpenStreetMap, Google Maps, Satellite) with built-in caching and automatic dark mode support.

Repository (GitHub)
View/report issues

Topics

#map #flutter-map #tiles #caching #openstreetmap

License

MIT (license)

Dependencies

dio_cache_interceptor, flutter, flutter_map, flutter_map_cache, http_cache_file_store, path_provider

More

Packages that depend on flutter_map_tile_switcher