Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flutter_map ^6.0.0 #2

Merged
merged 7 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [1.3.0] 2023-10-09

- Support for flutter_map version [^6.0.0](https://pub.dev/packages/flutter_map/changelog#600---20231009)
- Support to [cancel map tiles](https://github.com/fleaflet/flutter_map/pull/1622) if tiles are still loading but no
longer needed (
like [flutter_map_cancellable_tile_provider](https://pub.dev/packages/flutter_map_cancellable_tile_provider))
- Update documentation

## [1.2.0] 2023-06-28

#### CachedTileProvider
Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ Supported storage backends are:
- [x] [Drift (SQLite)](https://pub.dev/packages/drift)
- [x] [Hive](https://pub.dev/packages/hive)
- [x] [ObjectBox](https://pub.dev/packages/objectbox)
- [ ] [Isar](https://pub.dev/packages/isar) (planned,
see [dio_cache_interceptor#122](https://github.com/llfbandit/dio_cache_interceptor/issues/122))
- [ ] [Sembast](https://pub.dev/packages/sembast) (currently broken)

Support for [Isar](https://pub.dev/packages/isar) and other storage backends will be supported as soon as the
underlying package [dio_cache_interceptor](https://pub.dev/packages/dio_cache_interceptor) support them. See for
example issue [dio_cache_interceptor#122](https://github.com/llfbandit/dio_cache_interceptor/issues/122) that tracks
the support for isar.

## Getting started

Expand All @@ -52,7 +54,7 @@ dependencies:

## Usage

Using the cache is easy. Here is an example how to use the Hive backend:
Using the cache is easy. Here is an example how to use the **Hive** backend:

First get the cache directory of the app (i.e. with the [path_provider](https://pub.dev/packages/path_provider)
package).
Expand Down Expand Up @@ -92,7 +94,23 @@ Widget build(BuildContext context) {
}
```

## Common use cases
You can find additional example usages for other storage backends here:

- [In Memory (for testing)](https://github.com/josxha/flutter_map_cache/wiki/Use-the-In%E2%80%90Memory-Store-(for-testing))
- [File System](https://github.com/josxha/flutter_map_cache/wiki/Use-the-File-System)

## Common use cases & frequent questions

### How about web?

This package supports the web as long as you use a storage backend that supports web.

- In Memory works out of the box
- Hive uses for its web support IndexedDB under the hood to support web.
- Drift (SqLite) requires [additional setup steps for web](https://drift.simonbinder.eu/web/)

Additionally, this package has support to cancel tile requests that are no longer needed like the
[flutter_map_cancellable_tile_provider](https://pub.dev/packages/flutter_map_cancellable_tile_provider/) plugin.

### Remove the api key from the url before it gets used for caching

Expand Down
36 changes: 30 additions & 6 deletions example/lib/cache_store_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_db_store/dio_cache_interceptor_db_store.dart';
import 'package:dio_cache_interceptor_file_store/dio_cache_interceptor_file_store.dart';
import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart';
import 'package:dio_cache_interceptor_objectbox_store/dio_cache_interceptor_objectbox_store.dart';
import 'package:flutter/material.dart';

enum CacheStoreTypes {
memCache('MemCache'),
dbCache('DbCache (Drift)'),
fileCache('FileCache'),
hiveCache('HiveCache'),
// throws FormatException: Unexpected extension byte (at offset 0)
hiveCache('HiveCache');
//sembastCache('SembastCache'),
objectBoxCache('ObjectBoxCache');
//objectBoxCache('ObjectBoxCache');

const CacheStoreTypes(this.name);

Expand All @@ -32,12 +31,37 @@ enum CacheStoreTypes {
'$path${Platform.pathSeparator}HiveCacheStore',
hiveBoxName: 'HiveCacheStore',
),
CacheStoreTypes.objectBoxCache => ObjectBoxCacheStore(
/*CacheStoreTypes.objectBoxCache => ObjectBoxCacheStore(
storePath: '$path${Platform.pathSeparator}ObjectBoxCacheStore',
),
/*CacheStoreTypes.sembastCache => SembastCacheStore(
CacheStoreTypes.sembastCache => SembastCacheStore(
storePath: '$path${Platform.pathSeparator}SembastCacheStore',
cacheStore: 'SembastCacheStore',
),*/
};

CacheStore getCacheStoreWeb() => switch (this) {
CacheStoreTypes.memCache => MemCacheStore(),
CacheStoreTypes.dbCache => DbCacheStore(
databasePath: '', // ignored on web
databaseName: 'DbCacheStore',
),
CacheStoreTypes.fileCache => FileCacheStore(
'FileCacheStore',
),
CacheStoreTypes.hiveCache => HiveCacheStore(
'HiveCacheStore',
hiveBoxName: 'HiveCacheStore',
),
};

static List<DropdownMenuEntry<CacheStoreTypes>> get dropdownList =>
CacheStoreTypes.values
.map(
(e) => DropdownMenuEntry<CacheStoreTypes>(
value: e,
label: e.name,
),
)
.toList(growable: false);
}
27 changes: 27 additions & 0 deletions example/lib/example_app_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_map_cache_example/connectivity_icon.dart';

class ExampleAppWrapper extends StatelessWidget {
final Widget child;

const ExampleAppWrapper({required this.child, super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FlutterMap Cache',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
useMaterial3: true,
),
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterMap Cache'),
actions: const [ConnectivityIcon()],
),
body: child,
),
);
}
}
120 changes: 54 additions & 66 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'dart:io';

import 'package:dio/dio.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_cache/flutter_map_cache.dart';
import 'package:flutter_map_cache_example/cache_store_types.dart';
import 'package:flutter_map_cache_example/connectivity_icon.dart';
import 'package:latlong2/latlong.dart';
import 'package:flutter_map_cache_example/example_app_wrapper.dart';
import 'package:flutter_map_cache_example/misc.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(const ExampleApp());
Expand All @@ -20,67 +21,62 @@ class ExampleApp extends StatefulWidget {
}

class _ExampleAppState extends State<ExampleApp> {
late CacheStore _cacheStore = MemCacheStore();
CacheStore _cacheStore = MemCacheStore();

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FlutterMap Cache',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
useMaterial3: true,
),
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterMap Cache'),
actions: const [ConnectivityIcon()],
),
body: Column(
children: [
Expanded(
child: FlutterMap(
options: MapOptions(
center: const LatLng(47.141344, 9.553680),
interactiveFlags:
InteractiveFlag.all & ~InteractiveFlag.rotate,
maxZoom: 16,
zoom: 8,
),
children: [
TileLayer(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
tileProvider: CachedTileProvider(
maxStale: const Duration(days: 30),
store: _cacheStore,
interceptors: [
LogInterceptor(
logPrint: (object) => debugPrint(object.toString()),
responseHeader: false,
requestHeader: false,
request: false,
),
],
),
userAgentPackageName: 'com.github.josxha/flutter_map_cache',
return ExampleAppWrapper(
child: Column(
children: [
Expanded(
child: FlutterMap(
options: mapOptions,
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
tileProvider: CachedTileProvider(
maxStale: const Duration(days: 30),
store: _cacheStore,
interceptors: [
LogInterceptor(
logPrint: (object) => debugPrint(object.toString()),
responseHeader: false,
requestHeader: false,
request: false,
),
],
),
],
),
userAgentPackageName: 'com.github.josxha/flutter_map_cache',
),
],
),
Container(
color: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text('CacheStore Type'),
),
Container(
color: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text('CacheStore Type'),
if (kIsWeb)
DropdownMenu<CacheStoreTypes>(
initialSelection: CacheStoreTypes.memCache,
onSelected: (value) {
if (value == null) return;
debugPrint('CacheStore changed to ${value.name}');
setState(() {
_cacheStore = value.getCacheStoreWeb();
});
},
dropdownMenuEntries: CacheStoreTypes.dropdownList,
),
if (!kIsWeb)
FutureBuilder<Directory>(
// ignore: discarded_futures
future: getTemporaryDirectory(),
future: getTemporaryDirectory(), // not available on web
builder: (context, snapshot) {
if (snapshot.hasData) {
final dataPath = snapshot.data!.path;
final dataPath = snapshot.requireData.path;
return DropdownMenu<CacheStoreTypes>(
initialSelection: CacheStoreTypes.memCache,
onSelected: (value) {
Expand All @@ -90,14 +86,7 @@ class _ExampleAppState extends State<ExampleApp> {
_cacheStore = value.getCacheStore(dataPath);
});
},
dropdownMenuEntries: CacheStoreTypes.values
.map(
(e) => DropdownMenuEntry(
value: e,
label: e.name,
),
)
.toList(growable: false),
dropdownMenuEntries: CacheStoreTypes.dropdownList,
);
}
if (snapshot.hasError) {
Expand All @@ -110,11 +99,10 @@ class _ExampleAppState extends State<ExampleApp> {
return const Expanded(child: LinearProgressIndicator());
},
),
],
),
],
),
],
),
),
],
),
);
}
Expand Down
11 changes: 11 additions & 0 deletions example/lib/misc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';

const mapOptions = MapOptions(
initialCenter: LatLng(47.141344, 9.553680),
interactionOptions: InteractionOptions(
flags: InteractiveFlag.all & ~InteractiveFlag.rotate,
),
maxZoom: 16,
initialZoom: 8,
);
4 changes: 0 additions & 4 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

#include "generated_plugin_registrant.h"

#include <objectbox_flutter_libs/objectbox_flutter_libs_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) objectbox_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ObjectboxFlutterLibsPlugin");
objectbox_flutter_libs_plugin_register_with_registrar(objectbox_flutter_libs_registrar);
g_autoptr(FlPluginRegistrar) sqlite3_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin");
sqlite3_flutter_libs_plugin_register_with_registrar(sqlite3_flutter_libs_registrar);
Expand Down
1 change: 0 additions & 1 deletion example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
objectbox_flutter_libs
sqlite3_flutter_libs
)

Expand Down
2 changes: 0 additions & 2 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import FlutterMacOS
import Foundation

import connectivity_plus
import objectbox_flutter_libs
import path_provider_foundation
import sqlite3_flutter_libs

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
ObjectboxFlutterLibsPlugin.register(with: registry.registrar(forPlugin: "ObjectboxFlutterLibsPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
}
8 changes: 4 additions & 4 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ dependencies:
sdk: flutter
flutter_map_cache:
path: ../
flutter_map: ^5.0.0
flutter_map: ^6.0.0
latlong2: ^0.9.0
connectivity_plus: ^4.0.1
connectivity_plus: ^5.0.0
path_provider: ^2.0.15
dio: ^5.2.0+1
dio_cache_interceptor: ^3.4.2
dio_cache_interceptor_db_store: ^5.1.0
dio_cache_interceptor_file_store: ^1.2.2
dio_cache_interceptor_hive_store: ^3.2.1
dio_cache_interceptor_objectbox_store: ^1.1.1
#dio_cache_interceptor_objectbox_store: ^1.1.1
dio_cache_interceptor_sembast_storage: ^0.1.0
objectbox_flutter_libs: ^1.4.1 # ObjectBox
#objectbox_flutter_libs: ^2.3.1 # ObjectBox
sqlite3_flutter_libs: ^0.5.15 # Drift

dev_dependencies:
Expand Down
3 changes: 0 additions & 3 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
#include "generated_plugin_registrant.h"

#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <objectbox_flutter_libs/objectbox_flutter_libs_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
ObjectboxFlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ObjectboxFlutterLibsPlugin"));
Sqlite3FlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin"));
}
Loading