环境配置
Flutter 3.27.0+版本
jpush_flutter: ^3.1.6 以上版本
get: ^4.6.6
问题表现
目前仅见于华为鸿蒙4.2.0设备上,正常点击APP图标后启动运行APP正常,通过推送消息拉起APP后启动黑屏,如果APP存活于后台,点击推送将APP打开到前台时正常。
报错信息为:
FormatException: FormatException: Scheme not starting with alphabetic character (at character 1)
和极光的客服工程师团体排查几天后,依然问题相同,且在新起APP和demo中,未见此报错。
问题定位在GetX中,Flutter代码在尝试解析推送内容时进行了URI转换报错
问题修复
排除GetX和极光推送的问题后,将目光定为到flutter自身上,通过查看Flutter3.27.0的更新日志可以发现
安卓部分更新内容提到Set deep linking flag to true by default by @hannah-hyj in 52350
即将deep linking从默认关闭修改为默认打开,极光推送在华为设备上点击推送内容正好触发了deeplink解析,而getx框架解析路由字段时报错,导致黑屏,Debug模式下的报错信息为:
A GlobalKey was used multiple times inside one widget's child list.
The offending GlobalKey was: [LabeledGlobalKey<NavigatorState>#3c1f9
Key Created by default
The parent of the widgets with that key was:
_Focus InheritedScope
The first child to get instantiated with that key became:
Navigator-[LabeledGlobalKey<NavigatorState>#3c1f9 Key Created by default]
The second child that was to be instantiated with that key was:
_FocusInheritedscope
A GlobalKey can only be specified on one widget at a time in the widget tree.
See also: https://docs.flutter dev/testing/errors
解决方案
在android/app/src/AndroidManifest.xml中 <application>中添加
<meta-data android:name="flutter_deeplinking_enabled" android:value="false" />
将deeplinking功能手动设置为关闭即可
若希望避免iOS端问题,可以在plist文件中添加
<key>FlutterDeepLinkingEnabled</key>
<false />
来关闭iOS下的deeplink问题。