flutter_map_tile_caching icon indicating copy to clipboard operation
flutter_map_tile_caching copied to clipboard

[FEATURE] Implement `dispose` method

Open jokilic opened this issue 11 months ago • 4 comments

What do you want implemented?

I'm initializing and disposing a Flutter app within another Flutter app. That 'child' Flutter app uses flutter_map and I'm using flutter_map_tile_caching.

I'm initializing FMTC with await FMTC.initialise(). But when disposing that child app and then again opening it, triggering FMTC.initialise() will throw an error IsarError: Instance has already been opened.

Can you implement proper dispose method which would close all database links and everything else?

What other alternatives are available?

I initialized flutter_map_tile_caching within the parent Flutter app, but that is not very clean and I'm using the package within the parent app, which shouldn't happen because it's not used by the parent app at all...

Can you provide any other information?

No response

Severity

Annoying: Currently have to use workarounds

jokilic avatar Jul 28 '23 08:07 jokilic

Hey @jokilic,

FMTC isn't intended to be able to be closed and reopened, however, it should be possible for you to do.

Use the 'package:flutter_map_tile_caching/fmtc_module_api.dart' import in addition to the normal import. Also install Isar. You should then be able to access the underlying FMTCRegistry.instance. Then use unregister on every store (you can get the ID of a store name with DatabaseTools.hash method), and call .close() on the returned result. Also call recoveryDatabase.close() from the registry.

Note that this is advanced functionality, and if misused, may cause your app to crash.

JaffaKetchup avatar Jul 28 '23 10:07 JaffaKetchup

@JaffaKetchup

Thank you for your help. I've implemented it like you wrote and it works great.

This is the way I implemented the dispose method:

 /// Disposes [FlutterMapTileCaching]
  Future<void> disposeMapCaching() async {
    final databaseHash = DatabaseTools.hash('myMapStore');
    final isarInstance = FMTCRegistry.instance.unregister(databaseHash);

    await isarInstance?.close();
    await FMTCRegistry.instance.recoveryDatabase.close();
  }

This can be closed, thank you once again! 😄

jokilic avatar Aug 04 '23 11:08 jokilic

Hey @jokilic, no problem. Glad to hear that it worked. I'll leave this open for now, as a feature request.

JaffaKetchup avatar Aug 04 '23 11:08 JaffaKetchup

(@jokilic and others)

This feature is included in the new prerelease.

I'm pleased (and exhausted) to announce that the next (and hopefully final) prerelease is now available: https://pub.dev/packages/flutter_map_tile_caching/versions/9.0.0-dev.7. ObjectBox has finally arrived! A provisional CHANGELOG is available at https://pub.dev/packages/flutter_map_tile_caching/versions/9.0.0-dev.7/changelog#900---hundreds-of-hours---2024xxxx.

Some things to note:

  • #148
  • Importing functionality is not yet working
  • There is no gurantee for stability in this version: I have done basic testing only
  • There is little/no documentation available outside of what is in the code, including no migration info; I'll be happy to answer questions here, but some answers can be found in the CHANGELOG
  • No data from older versions will be available, but the databases will not be modified/deleted - check your storage space if necessary

I'm really eager to hear feedback. The number one thing I want to hear is that there are no(!?) crashes! But I also want to hear about bugs you've found. At this point, I cannot take further feature requests: I cannot afford the time to expand the scope of this further at the moment.

Please post feedback in #105.

JaffaKetchup avatar Mar 07 '24 21:03 JaffaKetchup