Skip to content

Commit 494c67f

Browse files
v7.1.2: Minor bug fixes and improvements (JaffaKetchup#102)
* Fixed migrator bug Fixed image provider bug * Updated pubspec version Updated CHANGELOG * Built Example Applications * Fixed equality bug within `FMTCImageProvider` * Removed unnecessary `await` keyword * Built Example Applications --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 701df58 commit 494c67f

File tree

8 files changed

+63
-27
lines changed

8 files changed

+63
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Many thanks to my sponsors, no matter how much or how little they donated. Spons
1313

1414
# Changelog
1515

16+
## [7.1.2] - 2023/02/18
17+
18+
* Minor bug fixes
19+
1620
## [7.1.1] - 2023/02/16
1721

1822
* Major bug fixes

lib/src/providers/image_provider.dart

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
3838
/// Used internally to safely and efficiently update the cache misses statistic
3939
static final Queue cacheMissesQueue = Queue();
4040

41-
/// Shorthand for `provider.settings`
42-
late final FMTCTileProviderSettings settings;
43-
4441
final Isar _db;
4542

4643
/// Create a specialised [ImageProvider] dedicated to 'flutter_map_tile_caching'
4744
FMTCImageProvider({
4845
required this.provider,
4946
required this.options,
5047
required this.coords,
51-
}) : settings = provider.settings,
52-
_db = FMTCRegistry.instance(provider.storeDirectory.storeName);
48+
}) : _db = FMTCRegistry.instance(provider.storeDirectory.storeName);
5349

5450
@override
5551
ImageStreamCompleter loadBuffer(
@@ -103,7 +99,7 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
10399
try {
104100
throw FMTCBrowsingError(throwError, throwErrorType!);
105101
} on FMTCBrowsingError catch (e) {
106-
settings.errorHandler?.call(e);
102+
provider.settings.errorHandler?.call(e);
107103
rethrow;
108104
}
109105
}
@@ -125,26 +121,28 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
125121
final bool needsCreating = existingTile == null;
126122
final bool needsUpdating = needsCreating
127123
? false
128-
: settings.behavior == CacheBehavior.onlineFirst ||
129-
(settings.cachedValidDuration != Duration.zero &&
124+
: provider.settings.behavior == CacheBehavior.onlineFirst ||
125+
(provider.settings.cachedValidDuration != Duration.zero &&
130126
DateTime.now().millisecondsSinceEpoch -
131127
existingTile.lastModified.millisecondsSinceEpoch >
132-
settings.cachedValidDuration.inMilliseconds);
128+
provider.settings.cachedValidDuration.inMilliseconds);
133129

134-
/*print('---------');
130+
/* DEBUG ONLY
131+
print('---------');
135132
print(networkUrl);
136133
print(matcherUrl);
137-
print(' Existing ID: ' + (existingTile?.id ?? 'None').toString());
138-
print(' Needs Creating: ' + needsCreating.toString());
139-
print(' Needs Updating: ' + needsUpdating.toString());
134+
print(' Store: ${provider.storeDirectory.storeName}');
135+
print(' Existing ID: ${existingTile?.id ?? 'None'}');
136+
print(' Needs Updating & Not Creating: $needsUpdating');
140137
*/
141138

142139
// Get any existing bytes from the tile, if it exists
143140
Uint8List? bytes;
144141
if (!needsCreating) bytes = Uint8List.fromList(existingTile.bytes);
145142

146143
// IF network is disabled & the tile does not exist THEN throw an error
147-
if (settings.behavior == CacheBehavior.cacheOnly && needsCreating) {
144+
if (provider.settings.behavior == CacheBehavior.cacheOnly &&
145+
needsCreating) {
148146
return finish(
149147
throwError:
150148
'Failed to load the tile from the cache because it was missing.',
@@ -208,12 +206,15 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
208206
);
209207

210208
// If an new tile was created over the tile limit, delete the oldest tile
211-
if (needsCreating && settings.maxStoreLength != 0) {
209+
if (needsCreating && provider.settings.maxStoreLength != 0) {
212210
unawaited(
213211
removeOldestQueue.add(
214212
() => compute(
215213
_removeOldestTile,
216-
[provider.storeDirectory.storeName, settings.maxStoreLength],
214+
[
215+
provider.storeDirectory.storeName,
216+
provider.settings.maxStoreLength,
217+
],
217218
),
218219
),
219220
);
@@ -233,15 +234,23 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
233234
@override
234235
bool operator ==(Object other) =>
235236
identical(this, other) ||
236-
(other is FMTCImageProvider && other.coords == coords);
237+
(other is FMTCImageProvider &&
238+
other.runtimeType == runtimeType &&
239+
other.coords == coords &&
240+
other.provider == provider &&
241+
other.options == options);
237242

238243
@override
239-
int get hashCode => coords.hashCode;
244+
int get hashCode => Object.hashAllUnordered([
245+
coords.hashCode,
246+
provider.hashCode,
247+
options.hashCode,
248+
]);
240249
}
241250

242251
Future<void> _removeOldestTile(List<Object> args) async {
243252
final db = Isar.openSync(
244-
[DbTileSchema, DbMetadataSchema],
253+
[DbStoreDescriptorSchema, DbTileSchema, DbMetadataSchema],
245254
name: DatabaseTools.hash(args[0] as String).toString(),
246255
inspector: false,
247256
);

lib/src/providers/tile_provider.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,22 @@ class FMTCTileProvider extends TileProvider {
7272
required TileLayer options,
7373
}) async =>
7474
await _tiles.get(DatabaseTools.hash(getTileUrl(coords, options))) != null;
75+
76+
@override
77+
bool operator ==(Object other) =>
78+
identical(this, other) ||
79+
(other is FMTCTileProvider &&
80+
other.runtimeType == runtimeType &&
81+
other.httpClient == httpClient &&
82+
other.settings == settings &&
83+
other.storeDirectory == storeDirectory &&
84+
other.headers == headers);
85+
86+
@override
87+
int get hashCode => Object.hashAllUnordered([
88+
httpClient.hashCode,
89+
settings.hashCode,
90+
storeDirectory.hashCode,
91+
headers.hashCode,
92+
]);
7593
}

lib/src/root/migrator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ class RootMigrator {
197197
}
198198

199199
// Delete store files
200-
if (deleteOldStructure) await oldStores.delete(recursive: true);
200+
if (deleteOldStructure && await oldStores.exists()) {
201+
await oldStores.delete(recursive: true);
202+
}
201203

202204
return results;
203205
}

lib/src/settings/tile_provider_settings.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,15 @@ class FMTCTileProviderSettings {
9595
other.behavior == behavior &&
9696
other.cachedValidDuration == cachedValidDuration &&
9797
other.maxStoreLength == maxStoreLength &&
98-
other.errorHandler == errorHandler);
98+
other.errorHandler == errorHandler &&
99+
other.obscuredQueryParams == obscuredQueryParams);
99100

100101
@override
101-
int get hashCode =>
102-
behavior.hashCode ^
103-
cachedValidDuration.hashCode ^
104-
maxStoreLength.hashCode ^
105-
errorHandler.hashCode;
102+
int get hashCode => Object.hashAllUnordered([
103+
behavior.hashCode,
104+
cachedValidDuration.hashCode,
105+
maxStoreLength.hashCode,
106+
errorHandler.hashCode,
107+
obscuredQueryParams.hashCode,
108+
]);
106109
}
-5 Bytes
Binary file not shown.
2.66 KB
Binary file not shown.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_map_tile_caching
22
description: Plugin for 'flutter_map' providing advanced caching functionality,
33
with ability to download map regions for offline use.
4-
version: 7.1.1
4+
version: 7.1.2
55
repository: https://github.com/JaffaKetchup/flutter_map_tile_caching
66
issue_tracker: https://github.com/JaffaKetchup/flutter_map_tile_caching/issues
77
documentation: https://fmtc.jaffaketchup.dev

0 commit comments

Comments
 (0)