@@ -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
242251Future <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 );
0 commit comments