flutter_map_tile_caching
flutter_map_tile_caching copied to clipboard
[BUG] FMTC prevents web compilation
What is the bug?
If we update to 7.x we can no longer compile the project.
: Error: The integer literal 8585861370448577604 can't be represented exactly in JavaScript.
metadata.g.dart:18
Try changing the literal to something that can be represented in Javascript. In Javascript 8585861370448577536 is the nearest value that can be represented exactly.
id: -8585861370448577604,
^^^^^^^^^^^^^^^^^^^
: Error: The integer literal 8117814053675000476 can't be represented exactly in JavaScript.
recovery.g.dart:18
Try changing the literal to something that can be represented in Javascript. In Javascript 8117814053675000832 is the nearest value that can be represented exactly.
id: -8117814053675000476,
^^^^^^^^^^^^^^^^^^^
: Error: The integer literal 1365152130637522244 can't be represented exactly in JavaScript.
store_descriptor.g.dart:18
Try changing the literal to something that can be represented in Javascript. In Javascript 1365152130637522176 is the nearest value that can be represented exactly.
id: 1365152130637522244,
^^^^^^^^^^^^^^^^^^^
: Error: The integer literal 5030120948284417748 can't be represented exactly in JavaScript.
tile.g.dart:18
Try changing the literal to something that can be represented in Javascript. In Javascript 5030120948284418048 is the nearest value that can be represented exactly.
id: -5030120948284417748,
^^^^^^^^^^^^^^^^^^^
: Error: The integer literal 5953778071269117195 can't be represented exactly in JavaScript.
tile.g.dart:43
Try changing the literal to something that can be represented in Javascript. In Javascript 5953778071269116928 is the nearest value that can be represented exactly.
id: 5953778071269117195,
^^^^^^^^^^^^^^^^^^^
: Error: The integer literal 0xcbf29ce484222325 can't be represented exactly in JavaScript.
tools.dart:14
Try changing the literal to something that can be represented in Javascript. In Javascript 0xcbf29ce484222000 is the nearest value that can be represented exactly.
int hash = 0xcbf29ce484222325;
^^^^^^^^^^^^^^^^^^
Failed to compile application.
What is the expected behaviour?
Being able to compile.
How can we reproduce this issue?
No response
Do you have a potential solution?
No response
Can you provide any other information?
No response
Platforms Affected
Android, iOS, Windows, MacOS, Linux
Severity
Fatal: Causes the application to crash
Frequency
Consistently: Always occurs at the same time and location
Requirements
- [X] I agree to follow this project's Code of Conduct
- [X] I have checked for known issues in the GitHub tracker and on the docs site
- [X] I have completed the pre-report checks listed on the docs site
- [X] If I am using FMTC in a proprietary project, I have read and understood this important legal notice
Hi @stx, This is a major oversight on my part. Of course FMTC isn't intended for use on web, but that doesn't mean it shouldn't compile. The issue lies with the reliance on Isar, which uses a code generator to generate type safe database models. The current workaround is to use conditional imports. But, as stated by the author of Isar in https://github.com/dart-lang/sdk/issues/50385, they are cumbersome to use. There is a proposal for conditionally imported libraries at https://github.com/dart-lang/language/issues/2235, but I doubt that will be merged any time soon. For the time being, I'll have to look into conditional imports, but that might take a while (major refactoring). For now, I'm afraid you'll have to stick to v6, my apologies. I'll try to have this resolved by the end of the week, but I am extremely busy at the moment. Thanks for your patience!
@stx Unfortunatley, due to the way code generators work, it may not be possible to use conditional imports here:

Therefore, we're a little stuck for now. Apologies. If you think there's a way to solve this, please do let me know!
See https://github.com/isar/isar/issues/686.
Just heard a little bit from Isar's maintainer: https://github.com/isar/isar/issues/686#issuecomment-1493325747. This is great news! v8 will support Isar v4 and flutter_map v4, and will not be released before those.
I have the same issue.
any progress yet? my web app wont compile now :S
Hey, Isar v4 is under active development and appears to be almost ready. I'm concentrating on the next release of FM for the moment, but then this should be coming soon!
There is a temporary solution for that:
-
Create 3 files:
-
Add to map_cache and map_cache_web:
import 'package:flutter_map/flutter_map.dart';
Future<void> initializeCache() async {}
TileProvider? tileProvider;
- Add to map_cache_mobile:
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
const cacheStore = 'mapStore';
Future<void> initializeCache() async {
await FlutterMapTileCaching.initialise();
await FMTC.instance(cacheStore).manage.createAsync();
}
TileProvider? tileProvider = FMTC.instance(cacheStore).getTileProvider();
- When you using map cache add conditional import:
import 'your_path_to/cache/map_cache.dart'
if (dart.library.io) 'your_path_to/cache/map_cache_mobile.dart'
if (dart.library.html) 'your_path_to/cache/map_cache_web.dart';
And use functions according to doc initializeCache on app start and tileProvider on map
import 'your_path_to/cache/map_cache.dart'
if (dart.library.io) 'your_path_to/cache/map_cache_mobile.dart'
if (dart.library.html) 'your_path_to/cache/map_cache_web.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializeCache();
runApp(const App());
}
import 'your_path_to/cache/map_cache.dart'
if (dart.library.io) 'your_path_to/cache/map_cache_mobile.dart'
if (dart.library.html) 'your_path_to/cache/map_cache_web.dart';
TileLayer(
urlTemplate: my_url_template,
userAgentPackageName: 'my_app',
tileProvider: tileProvider,
)