flutter_map_tile_caching 10.0.0-dev.3 copy "flutter_map_tile_caching: ^10.0.0-dev.3" to clipboard
flutter_map_tile_caching: ^10.0.0-dev.3 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 'package:flutter/material.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'src/screens/home/home.dart';
import 'src/screens/home/map_view/state/region_selection_provider.dart';
import 'src/screens/initialisation_error/initialisation_error.dart';
import 'src/screens/store_editor/store_editor.dart';
import 'src/shared/misc/shared_preferences.dart';
import 'src/shared/misc/store_metadata_keys.dart';
import 'src/shared/state/general_provider.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  sharedPrefs = await SharedPreferences.getInstance();

  Object? initErr;
  try {
    await FMTCObjectBoxBackend().initialise();
  } catch (err) {
    initErr = err;
  }

  await const FMTCStore('Test Store').manage.create();
  await const FMTCStore('Test Store').metadata.setBulk(
    kvs: {
      StoreMetadataKeys.urlTemplate.key:
          'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
      StoreMetadataKeys.behaviour.key: CacheBehavior.cacheFirst.name,
    },
  );

  runApp(_AppContainer(initialisationError: initErr));
}

class _AppContainer extends StatelessWidget {
  const _AppContainer({
    required this.initialisationError,
  });

  final Object? initialisationError;

  static final _routes = <String,
      ({
    Widget Function(BuildContext)? std,
    PageRoute Function(BuildContext, RouteSettings)? custom,
  })>{
    HomeScreen.route: (
      std: (BuildContext context) => const HomeScreen(),
      custom: null,
    ),
    StoreEditorPopup.route: (
      std: null,
      custom: (context, settings) => MaterialPageRoute(
            builder: (context) => const StoreEditorPopup(),
            settings: settings,
            fullscreenDialog: true,
          ),
    ),
    /*ManageOfflineScreen.route: (
      std: (BuildContext context) => ManageOfflineScreen(),
      custom: null,
    ),
    RegionSelectionScreen.route: (
      std: (BuildContext context) => const RegionSelectionScreen(),
      custom: null,
    ),
    ProfileScreen.route: (
      std: (BuildContext context) => const ProfileScreen(),
      custom: ({
        required Widget Function(
          BuildContext,
          Animation<double>,
          Animation<double>,
        ) pageBuilder,
        required RouteSettings settings,
      }) =>
          PageRouteBuilder(
            pageBuilder: pageBuilder,
            settings: settings,
            transitionsBuilder: (context, animation, _, child) {
              const begin = Offset(0, 1);
              const end = Offset.zero;
              const curve = Curves.ease;

              final tween =
                  Tween(begin: begin, end: end).chain(CurveTween(curve: curve));

              return SlideTransition(
                position: animation.drive(tween),
                child: child,
              );
            },
          ),
    ),*/
  };

  @override
  Widget build(BuildContext context) {
    final themeData = ThemeData(
      brightness: Brightness.light,
      useMaterial3: true,
      textTheme: GoogleFonts.ubuntuTextTheme(ThemeData.light().textTheme),
      colorSchemeSeed: Colors.teal,
      switchTheme: SwitchThemeData(
        thumbIcon: WidgetStateProperty.resolveWith(
          (states) => states.contains(WidgetState.selected)
              ? const Icon(Icons.check)
              : null,
        ),
      ),
    );

    if (initialisationError case final err?) {
      return MaterialApp(
        title: 'FMTC Demo (Initialisation Error)',
        theme: themeData,
        home: InitialisationError(err: err),
      );
    }

    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (_) => GeneralProvider(),
        ),
        /*ChangeNotifierProvider(
          create: (_) => MapProvider(),
          lazy: true,
        ),*/
        ChangeNotifierProvider(
          create: (_) => RegionSelectionProvider(),
          lazy: true,
        ), /*
        ChangeNotifierProvider(
          create: (_) => ConfigureDownloadProvider(),
          lazy: true,
        ),
        ChangeNotifierProvider(
          create: (_) => DownloadingProvider(),
          lazy: true,
        ),*/
      ],
      child: MaterialApp(
        title: 'FMTC Demo',
        restorationScopeId: 'FMTC Demo',
        theme: themeData,
        initialRoute: HomeScreen.route,
        onGenerateRoute: (settings) {
          final route = _routes[settings.name]!;
          if (route.custom != null) return route.custom!(context, settings);
          return MaterialPageRoute(builder: route.std!, settings: settings);
        },
      ),
    );
  }
}
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

Topics

#flutter-map #map #fmtc

Documentation

Documentation

Funding

Consider supporting this project:

github.com

License

unknown (license)

Dependencies

async, collection, dart_earcut, flat_buffers, flutter, flutter_map, http, latlong2, meta, objectbox, objectbox_flutter_libs, path, path_provider

More

Packages that depend on flutter_map_tile_caching