flutter
flutter copied to clipboard
Support Unicode null in Method Channel names
Steps to Reproduce
Linked to https://github.com/firebase/flutterfire/issues/9587
In FlutterFire, we are using channels with arbitrary names to listen to events emitted by native. It appears that using a channel that has a Unicode character; the channel will fail with
MissingPluginException (MissingPluginException(No implementation found for method getPlatformVersion on channel hello))
Expected results: We should be able to use Unicode characters in MethodChannels.
Actual results:
MissingPluginException (MissingPluginException(No implementation found for method getPlatformVersion on channel hello))
Code sample
By using `flutter create --org com.example --template=plugin --platforms=android,ios,linux,macos,windows -a kotlin hello``
And changing hello_method_channel.dart:10
final methodChannel = const MethodChannel('hello\u{0000}');
And android/src/main/kotlin/com/example/hello/HelloPlugin.kt:20 with
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "hello\u0000")
You will get the issue.
Logs
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.9, on macOS 13.0 22A380 darwin-arm, locale en-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.73.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
In FlutterFire, we are using channels with arbitrary names to listen to events emitted by native.
Can you elaborate on the usecase here? Why do you need to have channels whose names contain arbitrary strings?
It appears that using a channel that has a Unicode character; the channel will fail
Is this true of all unicode characters? You've shown the null byte, which is generally a string terminator.
The use case for FlutterFire is to create a method channel per request from the user and close the native listener properly when the subscription is closed. To create the name of those channels, we are using the values the user provides.
I've tried with a couple of other unicode characters and they all work 👍 It seems to be only the u{0000}
Null has a special meaning as a string terminator in some common representations. This isn't even possible to express without charging the C embedder API for the sole purpose of supporting this one character.
Given the complexity of getting this right across all implementions, and the fact that it seems like an extremely niche use case, I think we should probably just document that this character isn't supported.
Thanks for your help. I think we’ll just workaround this.
Closing this as working as intended.
@chinmaygarde Why is not having this documented WAI? The fact that null bytes aren't going to work isn't obvious in all contexts.
I glossed over the last sentence of your last reply where the issue was repurposed as an update to documentation. We closed this in triage as an issue asking to support null bytes in method channel names.
I've updated the title to match the ask and reopened.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.