googlemaps / flutter-navigation-sdk

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

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

Open yehuda-noiman opened 3 days ago

yehuda-noiman commented 3 days 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 2 days 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.