flutter_mapbox_navigation icon indicating copy to clipboard operation
flutter_mapbox_navigation copied to clipboard

Bad State exception on full-screen navigation

Open razaen801 opened this issue 2 years ago • 3 comments

E/flutter (15475): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Bad state: No element E/flutter (15475): #0 ListMixin.firstWhere (dart:collection/list.dart:167:5) E/flutter (15475): #1 new RouteEvent.fromJson (package:flutter_mapbox_navigation/models/routeEvent.dart:15:12) E/flutter (15475): #2 MapBoxNavigation._parseRouteEvent (package:flutter_mapbox_navigation/flutter_mapbox_navigation.dart:135:26) E/flutter (15475): #3 MapBoxNavigation._streamRouteEvent. (package:flutter_mapbox_navigation/flutter_mapbox_navigation.dart:122:35) E/flutter (15475): #4 _MapStream._handleData (dart:async/stream_pipe.dart:213:31) E/flutter (15475): #5 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13) E/flutter (15475): #6 _rootRunUnary (dart:async/zone.dart:1434:47) E/flutter (15475): #7 _CustomZone.runUnary (dart:async/zone.dart:1335:19) E/flutter (15475): #8 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) E/flutter (15475): #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) E/flutter (15475): #10 _DelayedData.perform (dart:async/stream_impl.dart:591:14) E/flutter (15475): #11 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11) E/flutter (15475): #12 _PendingEvents.schedule. (dart:async/stream_impl.dart:663:7) E/flutter (15475): #13 _rootRun (dart:async/zone.dart:1418:47) E/flutter (15475): #14 _CustomZone.run (dart:async/zone.dart:1328:19) E/flutter (15475): #15 _CustomZone.runGuarded (dart:async/zone.dart:1236:7) E/flutter (15475): #16 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1276:23) E/flutter (15475): #17 _rootRun (dart:async/zone.dart:1426:13) E/flutter (15475): #18 _CustomZone.run (dart:async/zone.dart:1328:19) E/flutter (15475): #19 _CustomZone.runGuarded (dart:async/zone.dart:1236:7) E/flutter (15475): #20 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1276:23) E/flutter (15475): #21 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) E/flutter (15475): #22 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Full screen navigation shows the given error i guess route array is missing, automatic zoom isnt working and the map lags too much

razaen801 avatar Mar 07 '22 10:03 razaen801

I am getting same error messages on Android devices. When navigation starts, camera does not automatically zoom in to user's location arrow. I had to move camera and then press on 're-center' button to make camera track user's location

scortumee avatar Mar 21 '22 19:03 scortumee

Same here, any fix?

lasd14 avatar Jun 09 '22 15:06 lasd14

Hello @scortumee @razaen801 I found a solution for this problem, I think these common problems are because we use the version of this package that is in pub.dev, but searching the github I found that there are some files that have already solved most of these problems. If we look at the routeEvent.dart package model we can see that in the fromJson we need to have a Try/Catch (on StateError) that handles this BadState Element error.

RouteEvent.fromJson(Map<String, dynamic> json) {
    if (json['eventType'] is int)
      eventType = MapBoxEvent.values[json['eventType']];
    else {
      try {
        eventType = MapBoxEvent.values.firstWhere(
          (e) => e.toString().split(".").last == json['eventType']);
      } on StateError {
        //When the list is empty or eventType is not found (BadState Element)
      } catch (e) {}
    }
    var dataJson = json['data'];
    if (eventType == MapBoxEvent.progress_change) {
      data = RouteProgressEvent.fromJson(dataJson);
    } else {
      data = jsonEncode(json['data']);
    }
  }

lasd14 avatar Jun 09 '22 16:06 lasd14

Stale issue message

eopeter avatar May 23 '23 01:05 eopeter