googlemaps / flutter-navigation-sdk

Google Navigation for Flutter plugin (Beta)
https://pub.dev/packages/google_navigation_flutter
Apache License 2.0
27 stars 11 forks source link

Navigation: Channel communication fails on iOS when integrating Turn-by-Turn navigation into a larger app #211

Open yehuda-noiman opened 1 week ago

yehuda-noiman commented 1 week ago

Environment details

  1. Flutter version 3.24.3, stable channel
  2. sonama 14.5, intel
  3. google_navigation_flutter: ^0.3.0 OS type and version: iOS iOS 16.7.10 but reproduced at any IOS we tried Library version and other environment information: Flutter version: 3.22.1 • channel stable google_navigation_flutter version: 0.3.0

Device model: (IPhone 8 plus, iPhone 12 Pro Max, more IOS devices) Steps to reproduce Integrate the google_navigation_flutter plugin into a large existing Flutter app. Implement the Turn-by-Turn navigation feature using code from the example app. Run the app on an iOS device or simulator. Attempt to start Turn-by-Turn navigation. Observe that the app fails due to channel communication issues. Expected behavior The Turn-by-Turn navigation should start and function as expected, just like it does in the example app provided by the google_navigation_flutter plugin. Actual behavior When attempting to start Turn-by-Turn navigation in the larger app, the app fails on channel communication. Specifically, the response in the onNavInfo function is nil, leading to a failure in the completion handler. from messages.g.swift /// Turn-by-Turn navigation events.

func onNavInfo(navInfo navInfoArg: NavInfoDto,
               completion: @escaping (Result<Void, FlutterError>) -> Void) {
    let channelName =
      "dev.flutter.pigeon.google_navigation_flutter.NavigationSessionEventApi.onNavInfo"
    let channel = FlutterBasicMessageChannel(
      name: channelName,
      binaryMessenger: binaryMessenger,
      codec: codec
    )
    channel.sendMessage([navInfoArg] as [Any?]) { response in
        guard let listResponse = response as? [Any?] else {
            // The code goes here and the response is nil
            completion(.failure(createConnectionError(withChannelName: channelName)))
            return
        }
        if listResponse.count > 1 {
            let code: String = listResponse[0] as! String
            let message: String? = nilOrValue(listResponse[1])
            let details: String? = nilOrValue(listResponse[2])
            completion(.failure(FlutterError(code: code, message: message, details: details)))
        } else {
            completion(.success(()))
        }
    }
}

Note: The comment // The code goes here and the response is nil indicates where the response is unexpectedly nil. Note2: The simulator works it's just that we don't get any events on the dart side

Additional Information: The Turn-by-Turn navigation works as expected when using the example app provided by the plugin. The issue only occurs when integrating the same code into a larger app. There might be a discrepancy in how the message channels are set up or how the binary messenger communicates in a larger app context. Please let me know if you'd like to add anything else or need further assistance!

jokerttu commented 1 week ago

Hi @yehuda-noiman, Thank you for reporting this issue.

To help us reproduce it, could you provide more details about the app context that’s causing the problem? If possible, sharing a partial implementation of your application that demonstrates the issue would be very helpful.

You can add a breakpoint at this line and verify that navInfo is properly handled and converted for the channel.

yehuda-noiman commented 5 days ago

hi the app is quite large things to NOTE

we are using many plugins and packages (ill send here the pubspec) as i said, it also failed when i copy pasted the turn_by_turn example in our project another thing note: before using this plugin we developed the plugin in house and the navigation and turn by turn worked, we just had some crashes from time to time so we decided to use the official plugin...

our pubspec.yaml

`name: courier_flutter
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 is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.

version: 2.1.26+2011385

environment:
  sdk: ">=3.0.0 <4.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.5

  ##### presentation #####

  # flutter_google_navigation_ux:
  #   # path: /Users/yehuda/development/NavigationPluginFlutter/flutter_google_navigation_ux
  #   git:
  #     url: "git@github.com:getpackageltd/NavigationPluginFlutter.git"
  #     #   url: "https://github.com/getpackageltd/NavigationPluginFlutter.git"
  #     ref: "main"
  #     path: "flutter_google_navigation_ux"

  flutter_bloc: ^8.1.1
  bloc_concurrency: ^0.2.5
  intl_phone_number_input: ^0.7.1
  pinput: ^5.0.0
  smart_auth: ^2.0.0
  intl: ^0.19.0
  cached_network_image: ^3.2.2
  flutter_animate: ^3.1.0
  country_icons: ^2.0.2
  dropdown_button2: ^2.3.9
  flutter_keyboard_visibility: ^5.4.0
  bottom_inset_observer: ^3.1.0
  flutter_svg: ^1.1.6
  inview_notifier_list: ^3.0.0
  flutter_callkit_incoming: ^2.0.0+1
  appsflyer_sdk: ^6.13.0+2
  mutex: ^3.1.0
  # date_utils: ^0.2.0
  camera: ^0.10.5+9
  flutter_countdown_timer: ^4.1.0
  google_fonts: ^4.0.4
  url_launcher: ^6.1.11
  blur: ^3.1.0
  modal_bottom_sheet: ^3.0.0-pre

  open_store: ^0.4.0
  transparent_image: ^2.0.0
  draggable_bottom_sheet: ^1.0.2
  toggle_switch: ^2.0.1
  snapping_sheet:
    path: ./snapping_sheet-3.1.0
  flutter_reorderable_list: ^1.2.0
  flutter_expandable_fab: ^1.6.1
  flutter_smartlook: ^4.1.23
  # flutter_map: ^3.1.0
  livechatt: "^1.4.0"
  onesignal_flutter: ^5.1.2
  flutter_advanced_switch: ^3.0.1
  flutter_slidable: ^3.1.0
  slide_switcher: ^1.1.2
  mobile_scanner: ^3.3.0
  hand_signature: ^3.0.1
  internet_connection_checker: ^1.0.0+1
  flutter_screenutil: ^5.7.0
  device_preview:
    git:
      url: "https://github.com/RuslanTsitser/flutter_device_preview.git"
      ref: "master"
      path: "device_preview"
  fl_chart: ^0.62.0
  image: ^3.2.2
  slide_countdown: ^0.5.0
  flutter_easyloading: ^3.0.5
  easy_rich_text: ^1.2.0
  flutter_image_compress: ^2.2.0
  gif: ^2.3.0
  flutter_localizations:
    sdk: flutter
  searchable_listview: ^2.4.0
  pdfx: ^2.6.0
  # pdfx:
  #   git:
  #     url: "https://github.com/getpackageltd/packages.flutter_pdfx.git"
  #     ref: "main"
  #     path: "packages/pdfx"

  ##### core #####
  firebase_remote_config: ^5.0.3
  maps_toolkit: ^2.0.1
  firebase_core: ^3.2.0
  google_static_maps_controller: ^1.0.0
  flutter_polyline_points: ^2.0.0
  flutter_local_notifications: ^15.0.0
  firebase_storage: ^12.1.1
  firebase_messaging: ^15.0.3
  firebase_analytics: ^11.2.0
  # awesome_notifications: ^0.7.4+1
  # awesome_notifications_fcm: ^0.7.4+1
  google_polyline_algorithm: ^3.1.0
  visibility_detector: ^0.4.0+2
  go_router: ^10.0.0
  flutter_google_maps_webservices: ^1.1.1
  shared_preferences: ^2.2.0
  share_plus: ^7.2.1
  sprintf: ^7.0.0
  logger: ^2.0.2+1
  device_info_plus: ^9.0.3
  isar: 3.1.0+1
  isar_flutter_libs: 3.1.0+1
  hive: ^2.2.3
  sentry_flutter: ^7.12.0
  sembast: ^3.6.0
  either_dart: ^0.2.0
  wakelock:
    git:
      url: "git@github.com:yehuda-noiman/wakelock.git"
      ref: "main"
      path: "wakelock"
  lottie: 2.0.0 # use latest after migrating to dart 3.0 (Because courier_flutter depends on lottie >=2.4.0 which requires SDK version ^3.0.0, version solving failed.)

  injectable: ^1.5.3
  get_it: ^7.2.0
  graphql: ^5.1.3
  fresh_graphql: ^0.6.0
  flutter_secure_storage: ^8.0.0

  collection: ^1.16.0
  jwt_decoder: ^2.0.1
  equatable: ^2.0.5
  enum_to_string: ^2.0.1
  auto_size_text: ^3.0.0
  phone_state: ^1.0.3
  # flutter_background_geolocation: ^4.13.5
  google_mlkit_face_detection: ^0.7.0
  tflite_flutter: ^0.10.1
  google_api_headers: ^2.0.3
  # google_maps_flutter: ^2.2.0
  google_maps_flutter:
    path: ./google_maps_flutter
  geolocator: ^13.0.1
  internet_file:
    git:
      url: "https://github.com/ScerIO/packages.dart.git"
      ref: "master"
      path: "packages/internet_file"
  datadog_flutter_plugin: ^2.4.0
  gql_dio_link: ^1.0.0
  pretty_dio_logger: ^1.3.1
  dio: ^5.2.1+1
  image_picker: ^1.0.1
  # background_location_tracker: ^1.4.0
  permission_handler: ^10.4.3
  background_locator_2:
    #  path: /Users/yehuda/development/background-locator
    git:
      url: "git@github.com:getpackageltd/getpackage-background-locator.git"
      #   url: "https://github.com/getpackageltd/NavigationPluginFlutter.git"
      ref: "main"

  path_provider: ^2.0.15
  google_navigation_flutter: ^0.4.0

dev_dependencies:
  integration_test:
    sdk: flutter
  flutter_test:
    sdk: flutter
  flutter_driver:
    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
  go_router_builder: any
  faker: ^2.1.0
  # flutter_foreground_task: ^3.10.0
  isar_generator: 3.1.0+1
  change_app_package_name: ^1.1.0
  bloc_test: ^9.1.0
  graphql_codegen: ^0.13.0
  build_runner: ^2.1.8
  injectable_generator: ^1.5.4
  json_serializable: ^6.5.3
  mockito: ^5.3.2
  icons_launcher: ^2.0.5
  flutter_native_splash: ^2.2.16
  mocktail: ^0.3.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
icons_launcher:
  image_path: "assets/images/store_logo.png"
  platforms:
    android:
      enable: true
    ios:
      enable: true
# 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.
  # generate: true
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - lib/l10n/
    - assets/images/
    - assets/backgrounds/
    - assets/icons/svg/
    - assets/mobilefacenet.tflite
    - assets/lottie_anim/
  # 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

it might be something to do with pigeon... we have alot of users in production using the app and we would really appreciate your assistance. thanks

yehuda-noiman commented 5 days ago

and as per where you told me to put a break point i already checked and it only fails at the messages.g.dart when using the channel to send the message to the dart side, meaning the issue is not there.