flutter_map_tile_caching 8.0.0-dev.6 copy "flutter_map_tile_caching: ^8.0.0-dev.6" to clipboard
flutter_map_tile_caching: ^8.0.0-dev.6 copied to clipboard

Plugin for 'flutter_map' providing advanced caching functionality, with ability to download map regions for offline use.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'screens/main/main.dart';
import 'shared/state/download_provider.dart';
import 'shared/state/general_provider.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.dark,
    ),
  );

  final SharedPreferences prefs = await SharedPreferences.getInstance();

  String? damagedDatabaseDeleted;
  await FlutterMapTileCaching.initialise(
    errorHandler: (error) => damagedDatabaseDeleted = error.message,
    debugMode: true,
  );

  await FMTC.instance.rootDirectory.migrator.fromV6(urlTemplates: []);

  if (prefs.getBool('reset') ?? false) {
    await FMTC.instance.rootDirectory.manage.reset();
  }

  final File newAppVersionFile = File(
    p.join(
      // ignore: invalid_use_of_internal_member, invalid_use_of_protected_member
      FMTC.instance.rootDirectory.directory.absolute.path,
      'newAppVersion.${Platform.isWindows ? 'exe' : 'apk'}',
    ),
  );
  if (await newAppVersionFile.exists()) await newAppVersionFile.delete();

  runApp(AppContainer(damagedDatabaseDeleted: damagedDatabaseDeleted));
}

class AppContainer extends StatelessWidget {
  const AppContainer({
    super.key,
    required this.damagedDatabaseDeleted,
  });

  final String? damagedDatabaseDeleted;

  @override
  Widget build(BuildContext context) => MultiProvider(
        providers: [
          ChangeNotifierProvider<GeneralProvider>(
            create: (context) => GeneralProvider(),
          ),
          ChangeNotifierProvider<DownloadProvider>(
            create: (context) => DownloadProvider(),
          ),
        ],
        child: MaterialApp(
          title: 'FMTC Example',
          theme: ThemeData(
            brightness: Brightness.dark,
            useMaterial3: true,
            textTheme: GoogleFonts.openSansTextTheme(const TextTheme()),
            colorSchemeSeed: Colors.deepOrange,
            switchTheme: SwitchThemeData(
              thumbIcon: MaterialStateProperty.resolveWith(
                (states) => Icon(
                  states.contains(MaterialState.selected)
                      ? Icons.check
                      : Icons.close,
                ),
              ),
            ),
          ),
          debugShowCheckedModeBanner: false,
          home: MainScreen(damagedDatabaseDeleted: damagedDatabaseDeleted),
        ),
      );
}
115
likes
0
pub points
95%
popularity

Publisher

verified publisherjaffaketchup.dev

Plugin for 'flutter_map' providing advanced caching functionality, with ability to download map regions for offline use.

Repository (GitHub)
View/report issues

Documentation

Documentation

Funding

Consider supporting this project:

github.com

License

unknown (license)

Dependencies

async, collection, flutter, flutter_map, http, http_plus, isar, isar_flutter_libs, latlong2, meta, path, path_provider, queue, stream_transform, watcher

More

Packages that depend on flutter_map_tile_caching