flutter_mapbox_navigation
flutter_mapbox_navigation copied to clipboard
Bad State exception on full-screen navigation
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.
Full screen navigation shows the given error i guess route array is missing, automatic zoom isnt working and the map lags too much
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
Same here, any fix?
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']);
}
}
Stale issue message