apptreesoftware / flutter_google_map_view

A flutter plugin for Google Maps
MIT License
416 stars 189 forks source link

Event handlers in example not firing due to exception #45

Open myleftshoe opened 6 years ago

myleftshoe commented 6 years ago

This code in the example throws an exception on the .listens. This effectively disables all the event handlers except the one that throws the exception, i.e the first one. Here .listen((location ... fails which means the following aren't executed. If I comment it out, the exception is thrown on the next.

If I wrap each in a try-catch to ignore the errors the handlers still work. That's my work-around for now.

    sub = mapView.onLocationUpdated
        .listen((location) => print("Location updated $location"));
    compositeSubscription.add(sub);

    sub = mapView.onTouchAnnotation
        .listen((annotation) => print("annotation tapped"));
    compositeSubscription.add(sub);

    sub = mapView.onMapTapped
        .listen((location) => print("Touched location $location"));
    compositeSubscription.add(sub);

    sub = mapView.onCameraChanged.listen((cameraPosition) =>
        this.setState(() => this.cameraPosition = cameraPosition));
    compositeSubscription.add(sub);

    sub = mapView.onToolbarAction.listen((id) {
      if (id == 1) {
        _handleDismiss();
      }
    });
    compositeSubscription.add(sub);

    sub = mapView.onInfoWindowTapped.listen((marker) {
      print("Info Window Tapped for ${marker.title}");
    });
    compositeSubscription.add(sub);
  }
I/flutter (10026): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (10026): The following assertion was thrown while handling a gesture:
I/flutter (10026): type '_BroadcastSubscription<Location>' is not a subtype of type 'StreamSubscription<Null>' where
I/flutter (10026):   _BroadcastSubscription is from dart:async
I/flutter (10026):   Location is from package:map_view/location.dart
I/flutter (10026):   StreamSubscription is from dart:async
I/flutter (10026):   Null is from dart:core
I/flutter (10026): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (10026): more information in this error message to help you determine and fix the underlying cause.
I/flutter (10026): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (10026):   https://github.com/flutter/flutter/issues/new
I/flutter (10026): When the exception was thrown, this was the stack:
I/flutter (10026): #0      _MyAppState.showMap (file:///C:/Users/Paul/Documents/flutter/map_view_example/lib/main.dart:125:10)
I/flutter (10026): #1      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:490:14)
I/flutter (10026): #2      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:545:30)
I/flutter (10026): #3      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
I/flutter (10026): #4      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
I/flutter (10026): #5      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
I/flutter (10026): #6      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
I/flutter (10026): #7      PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
I/flutter (10026): #8      PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
I/flutter (10026): #9      _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
I/flutter (10026): #10     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
I/flutter (10026): #11     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
I/flutter (10026): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
I/flutter (10026): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
I/flutter (10026): #14     _invoke1 (dart:ui/hooks.dart:134:13)
I/flutter (10026): #15     _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)
I/flutter (10026): Handler: onTap
I/flutter (10026): Recognizer:
I/flutter (10026):   TapGestureRecognizer#39b2f(debugOwner: GestureDetector, state: possible, won arena, finalPosition:
I/flutter (10026):   Offset(283.7, 182.2), sent tap down)
I/flutter (10026): ════════════════════════════════════════════════════════════════════════════════════════════════════
vagrantrobbie commented 6 years ago

I have this too. Will wrap a try catch around each of the stream handlers as well for now but would be great if we could get a fix

matthewtsmith commented 6 years ago

This is a Dart 2 type check error. We have not had the bandwidth to upgrade this project to Dart 2 yet.

abjorck commented 6 years ago

I did some patches and updates to get it working on the latest for me (android only tested)

47 may it help someone

takaoandrew commented 6 years ago

I'm having the same issue, but wrapping all the listen functions in try catch is not helping. Whenever I touch the map my app crashes. I've tried this-- Wasn't sure if I was to include the first listen function where "var sub" was first defined, but tried pulling out "var sub;" and then putting that sub = mapView.onMapReady... etc in try catch and still was crashing.

showMap() { mapView.show( new MapOptions( mapViewType: MapViewType.normal, showUserLocation: true, initialCameraPosition: new CameraPosition( new Location(45.5235258, -122.6732493), 14.0), title: "Recently Visited"), toolbarActions: [new ToolbarAction("Close", 1)]);

var sub = mapView.onMapReady.listen((_) {
  mapView.setMarkers(_markers);
  mapView.addMarker(new Marker("3", "10 Barrel", 45.5259467, -122.687747,
      color: Colors.purple));
  mapView.zoomToFit(padding: 100);
});
compositeSubscription.add(sub);

try {
  sub = mapView.onLocationUpdated
      .listen((location) => print("Location updated $location"));
  compositeSubscription.add(sub);
}catch(e) {
  print("Error = " + e.toString());
}

try {
  sub = mapView.onTouchAnnotation
      .listen((annotation) => print("annotation tapped"));
  compositeSubscription.add(sub);
}catch(e) {
  print("Error = " + e.toString());
}

try {
  sub = mapView.onMapTapped
      .listen((location) => print("Touched location $location"));
  compositeSubscription.add(sub);
}catch(e) {
  print("Error = " + e.toString());
}

try {
  sub = mapView.onCameraChanged.listen((cameraPosition) =>
      this.setState(() => this.cameraPosition = cameraPosition));
  compositeSubscription.add(sub);
}catch(e) {
  print("Error = " + e.toString());
}

try {
  sub = mapView.onToolbarAction.listen((id) {
    if (id == 1) {
      _handleDismiss();
    }
  });
  compositeSubscription.add(sub);
}catch(e) {
  print("Error = " + e.toString());
}

try {
  sub = mapView.onInfoWindowTapped.listen((marker) {
    print("Info Window Tapped for ${marker.title}");
  });
  compositeSubscription.add(sub);
}catch(e) {
  print("Error = " + e.toString());
}

}

After clicking on the map, and after printing all of the error messages from catching, I get this error.

`I/art ( 9837): Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbfm; I/art ( 9837): at void com.apptreesoftware.mapview.MapViewPlugin.() (MapViewPlugin.kt:-1) I/art ( 9837): at void com.apptreesoftware.mapview.MapViewPlugin.registerWith(io.flutter.plugin.common.PluginRegistry$Registrar) (MapViewPlugin.kt:-1) I/art ( 9837): at void io.flutter.plugins.GeneratedPluginRegistrant.registerWith(io.flutter.plugin.common.PluginRegistry) (GeneratedPluginRegistrant.java:35) I/art ( 9837): at void com.takaoandrew.flutteralight.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:12) I/art ( 9837): at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6955) I/art ( 9837): at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1126) I/art ( 9837): at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2927) I/art ( 9837): at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:3045) I/art ( 9837): at void android.app.ActivityThread.-wrap14(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1) I/art ( 9837): at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1642) I/art ( 9837): at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102) I/art ( 9837): at void android.os.Looper.loop() (Looper.java:154) I/art ( 9837): at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6776) I/art ( 9837): at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2) I/art ( 9837): at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:1520) I/art ( 9837): at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1410) I/art ( 9837): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzbfm" on path: DexPathList[[zip file "/data/app/com.takaoandrew.flutteralight-2/base.apk"],nativeLibraryDirectories=[/data/app/com.takaoandrew.flutteralight-2/lib/arm64, /data/app/com.takaoandrew.flutteralight-2/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]] I/art ( 9837): at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56) I/art ( 9837): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380) I/art ( 9837): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312) I/art ( 9837): at void com.apptreesoftware.mapview.MapViewPlugin.() (MapViewPlugin.kt:-1) I/art ( 9837): at void com.apptreesoftware.mapview.MapViewPlugin.registerWith(io.flutter.plugin.common.PluginRegistry$Registrar) (MapViewPlugin.kt:-1) I/art ( 9837): at void io.flutter.plugins.GeneratedPluginRegistrant.registerWith(io.flutter.plugin.common.PluginRegistry) (GeneratedPluginRegistrant.java:35) I/art ( 9837): at void com.takaoandrew.flutteralight.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:12) I/art ( 9837): at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6955) I/art ( 9837): at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1126) I/art ( 9837): at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2927) I/art ( 9837): at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:3045) I/art ( 9837): at void android.app.ActivityThread.-wrap14(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1) I/art ( 9837): at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1642) I/art ( 9837): at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102) I/art ( 9837): at void android.os.Looper.loop() (Looper.java:154) I/art ( 9837): at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6776) I/art ( 9837): at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2) I/art ( 9837): at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:1520) I/art ( 9837): at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1410) I/art ( 9837): F/flutter ( 9837): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(60)] Check failed: CheckException(env). F/libc ( 9837): Fatal signal 6 (SIGABRT), code -6 in tid 9837 (w.flutteralight)


Build fingerprint: 'samsung/dreamqltesq/dreamqltesq:7.0/NRD90M/G950USQS2BRB1:user/release-keys' Revision: '12' ABI: 'arm64' pid: 9837, tid: 9837, name: w.flutteralight >>> com.takaoandrew.flutteralight <<< signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr -------- Abort message: '[FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(60)] Check failed: CheckException(env). ' x0 0000000000000000 x1 000000000000266d x2 0000000000000006 x3 0000000000000008 x4 0000007f99402140 x5 0000007f9920c7b0 x6 91d768a787abff12 x7 000000003a380770 x8 0000000000000083 x9 0000007f9dd36a98 x10 91d768a787abff12 x11 91d768a787abff12 x12 0000000000000000 x13 0000000000000020 x14 ffffffffffffffdf x15 0000007f99726810 x16 0000007f9971bee0 x17 0000007f996bc6bc x18 0000000000000090 x19 0000007f9dd36b40 x20 0000000000000006 x21 0000007f9dd36a98 x22 000000000000000b x23 0000007f68846a48 x24 0000007f8d620268 x25 0000007f74923000 x26 0000007f8d620268 x27 0000007f74923050 x28 000120f047ce4e54 x29 0000007fccd8b800 x30 0000007f996b9924 sp 0000007fccd8b7e0 pc 0000007f996bc6c4 pstate 0000000060000000 backtrace:

00 pc 000000000007a6c4 /system/lib64/libc.so (tgkill+8)

#01 pc 0000000000077920  /system/lib64/libc.so (pthread_kill+64)
#02 pc 000000000002538c  /system/lib64/libc.so (raise+24)
#03 pc 000000000001d24c  /system/lib64/libc.so (abort+52)
#04 pc 00000000003a9e48  /data/app/com.takaoandrew.flutteralight-2/lib/arm64/libflutter.so
#05 pc 00000000003aa590  /data/app/com.takaoandrew.flutteralight-2/lib/arm64/libflutter.so
#06 pc 00000000001628c8  /data/app/com.takaoandrew.flutteralight-2/lib/arm64/libflutter.so
#07 pc 0000000000161030  /data/app/com.takaoandrew.flutteralight-2/lib/arm64/libflutter.so
#08 pc 00000000001ab578  /data/app/com.takaoandrew.flutteralight-2/lib/arm64/libflutter.so
#09 pc 000000000016ec94  /data/app/com.takaoandrew.flutteralight-2/lib/arm64/libflutter.so
#10 pc 00000000001731ec  /data/app/com.takaoandrew.flutteralight-2/lib/arm64/libflutter.so
#11 pc 000000000001874c  /system/lib64/libutils.so (_ZN7android6Looper9pollInnerEi+892)
#12 pc 0000000000018310  /system/lib64/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+60)
#13 pc 00000000000f7c50  /system/lib64/libandroid_runtime.so (_ZN7android18NativeMessageQueue8pollOnceEP7_JNIEnvP8_jobjecti+48)
#14 pc 0000000002a07ac0  /system/framework/arm64/boot-framework.oat (offset 0x2014000) (android.os.MessageQueue.nativePollOnce+140)
#15 pc 0000000002a096e0  /system/framework/arm64/boot-framework.oat (offset 0x2014000) (android.os.MessageQueue.next+236)
#16 pc 0000000002a031f8  /system/framework/arm64/boot-framework.oat (offset 0x2014000) (android.os.Looper.loop+340)
#17 pc 00000000020e7670  /system/framework/arm64/boot-framework.oat (offset 0x2014000) (android.app.ActivityThread.main+732)
#18 pc 00000000000d2868  /system/lib64/libart.so (art_quick_invoke_static_stub+600)
#19 pc 00000000000df714  /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+260)
#20 pc 0000000000476c4c  /system/lib64/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+108)
#21 pc 0000000000478de8  /system/lib64/libart.so (_ZN3art12InvokeMethodERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectS4_S4_m+1212)
#22 pc 00000000003df204  /system/lib64/libart.so (_ZN3artL13Method_invokeEP7_JNIEnvP8_jobjectS3_S3_+52)
#23 pc 0000000000673378  /system/framework/arm64/boot.oat (offset 0x5a2000) (java.lang.reflect.Method.invoke+180)
#24 pc 00000000031c6b60  /system/framework/arm64/boot-framework.oat (offset 0x2014000) (com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run+124)
#25 pc 00000000031c86c0  /system/framework/arm64/boot-framework.oat (offset 0x2014000) (com.android.internal.os.ZygoteInit.main+1612)
#26 pc 00000000000d2868  /system/lib64/libart.so (art_quick_invoke_static_stub+600)
#27 pc 00000000000df714  /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+260)
#28 pc 0000000000476c4c  /system/lib64/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+108)
#29 pc 000000000047669c  /system/lib64/libart.so (_ZN3art17InvokeWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDSt9__va_list+372)
#30 pc 000000000037e7f0  /system/lib64/libart.so (_ZN3art3JNI21CallStaticVoidMethodVEP7_JNIEnvP7_jclassP10_jmethodIDSt9__va_list+596)
#31 pc 00000000000a5278  /system/lib64/libandroid_runtime.so
#32 pc 00000000000a7a88  /system/lib64/libandroid_runtime.so (_ZN7android14AndroidRuntime5startEPKcRKNS_6VectorINS_7String8EEEb+712)
#33 pc 0000000000004f20  /system/bin/app_process64
#34 pc 000000000001a90c  /system/lib64/libc.so (__libc_init+88)
#35 pc 0000000000004570  /system/bin/app_process64`

I feel like this might be an issue with other dependencies I have, but am not sure how to fix dependency issues... But this is my pubspec.yaml dependencies

image_picker: 0.4.1
google_sign_in: 3.0.3
firebase_analytics: 0.3.3
firebase_auth: 0.5.8
firebase_core: 0.2.3 firebase_database: 0.4.6
firebase_storage: 0.3.4 location: "^1.2.0" path_provider: "^0.4.0" audioplayer: "^0.4.0" url_launcher: "^3.0.1" map_view: "^0.0.11" sensors: "^0.3.2"

Thanks for any advice!

dancingbannana commented 6 years ago

I am fairly new to coding (self taught) so Im not too sure what I am doing but after hours of testing I got it to work by changing google_sign_in: 3.0.3 to google_sign_in: "^2.1.2" and compile 'com.google.firebase:firebase-core:16.0.0' to implementation 'com.google.firebase:firebase-core:11.8.0' I dont know why this works but it does

shoheietzel commented 6 years ago

Change "Set _subscriptions = new Set();" to "Set<StreamSubscription> _subscriptions = new Set();"

fromparis commented 6 years ago

@shoheietzel where do you change that exactly?

youssefhassan commented 6 years ago

Hey,

I had the same issue and fixed it just by declaring each sub on its own .. because by assigning the value to "sub" changes its type .. so either specify "sub" explicitly or define different sub varibales (sub1, sub2, ...)