Reputation: 36
I am new to Flutter and trying to integrate a MapBox map with Turn by Turn navigation in an iOS and Android app.
I am using the flutter_mapbox_navigation package and MapBoxNavigationView.
I cannot run the iOS app anymore as it always crashes a few seconds after launch. It was working before but now it crashes and I do not understand why. I do not see any error message or log or anything.
I tried commenting the Center
widget and all its children and it works fine.
I am on macOS Monterey 12.3.1 (Apple M1)
Console output:
Launching lib/main.dart on iPhone SE (3rd generation) in debug mode...
lib/main.dart:1
Xcode build done. 11,4s
Connecting to VM Service at ws://127.0.0.1:49961/xmxNQnLdNHE=/ws
Lost connection to device.
Exited
main.dart
import 'package:flutter/material.dart';
import 'package:flutter_mapbox_navigation/library.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
final _options = MapBoxOptions();
Future<void> _onRouteEvent(e) async {}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Column(
children: [
const Text("test"),
Center(
child: SizedBox(
width: 300,
height: 200,
child: MapBoxNavigationView(
options: _options,
onRouteEvent: _onRouteEvent,
onCreated: (MapBoxNavigationViewController controller) async {},
),
),
),
],
),
);
}
}
pubspec.yml
name: poc
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.17.0 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
flutter_mapbox_navigation: ^0.0.26
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Upvotes: 0
Views: 1192
Reputation: 11
I have been dealing with this problem too for a while. Try one of these:
Info.plist
"(Referencing: issue:463)
I resolved the issue by opening "ios/Runner/Info.plist
" and adding the
following lines in between the
<dict>...</dict>
.
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>MGLMapboxMetricsEnabledSettingShownInApp</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Shows your location on the map and helps improve the map</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Shows your location on the map and helps improve the map</string>
Also, execute the following commands in the root folder:
flutter clean
(to clean up the project)
flutter create .
(to add any missing files)
For me, the method above didn't work but it seemed to have worked for others so I thought it was worth mentioning. It seems that Mapbox has a hard time working on Apple Silicon iOS simulators(ref: https://github.com/mapbox/mapbox-gl-native-ios/issues/558)
But running it on your own device seems to work, at least for me. Following this: https://codeburst.io/wireless-debugging-ios-run-debug-install-builds-over-wifi-a48fc49ac3a7 you can run it wirelessly on your iPhone. Hope this helps.
PS: If you get the "iproxy cannot be opened because the developer cannot be verified", you can delete the /flutter/bin/cache/artifacts
directory and run flutter run
again.
Upvotes: 1