a14n / dart-google-maps

A library to use Google Maps JavaScript API v3 from Dart scripts.
Apache License 2.0
130 stars 66 forks source link

Error with > 7.00 version : Uncaught (in promise) TypeError: Illegal constructor #124

Closed alaindeseine closed 7 months ago

alaindeseine commented 7 months ago

Hi,

i use google_maps version 6.3.0 without any problems. I tried to use 7.0.0 and just know 7.1.0 but got an error at execution time. There is no errors, no warning in VSCode.

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.0, on macOS 12.7.3 21H1015 darwin-x64, locale fr-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.86.0)
[✓] Connected device (3 available)
[✓] Network resources

Here is the implementation code (partial).

6.3.0 code (working code):

      _mapOptions = MapOptions()
        ..mapTypeId = gmapUtils!.getMapTypeFromPref()
        ..zoom = 8
        ..center = LatLng(51.5, 2.50)
        ..fullscreenControl = false // removes the full screen button
        ..scaleControl = true
        ..zoomControl = true
        ..clickableIcons = true
        ..zoomControlOptions =
            (ZoomControlOptions()..position = ControlPosition.RIGHT_BOTTOM)
        ..mapTypeControlOptions = (MapTypeControlOptions()
          ..style = MapTypeControlStyle.HORIZONTAL_BAR
          ..position = ControlPosition.TOP_RIGHT);

      final elem =DivElement()
        ..id = htmlId
        ..style.width = "100%"
        ..style.height = "100%"
        ..style.border = 'none';

      map = GMap(elem, _mapOptions);

adapted 7.0.0 (or 7.1.0) code (errored code):

import 'package:web/web.dart' as web;
 ...

      _mapOptions = MapOptions()
        ..mapTypeId = gmapUtils!.getMapTypeFromPref()
        ..zoom = 8
        ..center = LatLng(51.5, 2.50)
        ..fullscreenControl = false // removes the full screen button
        ..scaleControl = true
        ..zoomControl = true
        ..clickableIcons = true
        ..zoomControlOptions =
            (ZoomControlOptions()..position = ControlPosition.RIGHT_BOTTOM)
        ..mapTypeControlOptions = (MapTypeControlOptions()
          ..style = MapTypeControlStyle.HORIZONTAL_BAR
          ..position = ControlPosition.TOP_RIGHT);

      final elem = web.HTMLElement() // Also tried with web.HTMLDivElement() 
        ..id = htmlId
        ..style.width = "100%"
        ..style.height = "100%"
        ..style.border = 'none';

      map = GMap(elem, _mapOptions);

Chrome (Version 122.0.6261.57) devtools console:

image

Any ideas?

a14n commented 7 months ago

If you use google_maps in a flutter app you shouldn't depend directly on google_maps and wait the plugin update (see https://github.com/flutter/packages/pull/5254).