flutter_map_tile_caching icon indicating copy to clipboard operation
flutter_map_tile_caching copied to clipboard

[BUG] FMTC prevents web compilation

Open stx opened this issue 2 years ago • 8 comments
trafficstars

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

stx avatar Feb 15 '23 06:02 stx

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!

JaffaKetchup avatar Feb 15 '23 08:02 JaffaKetchup

@stx Unfortunatley, due to the way code generators work, it may not be possible to use conditional imports here:

image

Therefore, we're a little stuck for now. Apologies. If you think there's a way to solve this, please do let me know!

JaffaKetchup avatar Feb 15 '23 21:02 JaffaKetchup

See https://github.com/isar/isar/issues/686.

JaffaKetchup avatar Feb 18 '23 11:02 JaffaKetchup

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.

JaffaKetchup avatar Apr 03 '23 09:04 JaffaKetchup

I have the same issue.

wikylyu avatar Aug 23 '23 06:08 wikylyu

any progress yet? my web app wont compile now :S

tik1111 avatar Sep 12 '23 17:09 tik1111

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!

JaffaKetchup avatar Sep 12 '23 17:09 JaffaKetchup

There is a temporary solution for that:

  1. Create 3 files: Zrzut ekranu 2023-09-30 o 12 47 49

  2. Add to map_cache and map_cache_web:

import 'package:flutter_map/flutter_map.dart';

Future<void> initializeCache() async {}

TileProvider? tileProvider;
  1. 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();
  1. 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,
                      )

slawekkrol avatar Sep 30 '23 10:09 slawekkrol