appcues / appcues-flutter-plugin

The Appcues Flutter Plugin Package
MIT License
6 stars 0 forks source link

Example app might block #74

Open chenfisher opened 6 months ago

chenfisher commented 6 months ago

I believe there's a bug in the example app:

Android, MainActivity:

        MethodChannel(flutterEngine.dartExecutor, CHANNEL).setMethodCallHandler { call, result ->
            if (call.method == "initialLink") {
                if (startString != null) {
                    result.success(startString)
                }
            }
        }

In most cases, the app is launched "normally" and not through a deep link, which means startString would be null.

if startString is null or if the method is not initialLink, no result will be sent to the Flutter end. If the caller is using await, the code would block indefinitely.

In your Flutter code, you use then on the future, and therefore do not see the blocking issue:

    _startUri().then(_onRedirected);

But if your code would have used async/await it would not have worked.

A possible solution would be to send a result in any case:

        MethodChannel(flutterEngine.dartExecutor, CHANNEL).setMethodCallHandler { call, result ->
            if (call.method == "initialLink") {
                result.success(startString)
            }

            result.error(...)
        }
  1. https://github.com/appcues/appcues-flutter-plugin/blob/68c35fb8e62e2cc5b8836b2f273a4cda0791e51e/example/android/app/src/main/kotlin/com/appcues/samples/flutter/MainActivity.kt#L25

  2. https://github.com/appcues/appcues-flutter-plugin/blob/68c35fb8e62e2cc5b8836b2f273a4cda0791e51e/example/lib/src/app.dart#L64

andretortolano commented 5 months ago

Thank you for the feedback, we will look into that