flutter_boost android 的degug版本正常, release打开app白屏

ecfdbz9o  于 2022-11-19  发布在  Flutter
关注(0)|答案(8)|浏览(248)

#937 中的问题,依然存在,环境如下,issue中的解决方案不适用于现在了,api已不存在
flutter_boost 3.1.2
Flutter 2.2.3 • channel stable

release模式启动后一直白屏,无论退出App几次依旧如此,并且控制台抛出异常如下:
注:debug模式下,首次安装也会白屏,也是如下异常,杀进程退出app后,可正常进入

[ +31 ms] I/flutter ( 739): -------初始化----------
[ +4 ms] V/FlutterBoostPlugin( 739): ## onForeground: com.idlefish.flutterboost.Messages$FlutterRouterApi@b5ff690
[ +2 ms] I/flutter ( 739): FlutterBoost#Oops, Failed to update overlay. mode=BoostSpecificEntryRefreshMode.add, BoostContainer(name:/, pages:[BoostPage(name:/, uniqueId:1664272815879_/, arguments:null)])
[ ] I/flutter ( 739): Null check operator used on a null value
[ ] I/flutter ( 739): #0 BoostChannel.addEventListener (package:flutter_boost/src/boost_channel.dart:34)
[ ] I/flutter ( 739): #1 FlutterBoostAppState._addAppLifecycleStateEventListener (package:flutter_boost/src/flutter_boost_app.dart:118)
[ ] I/flutter ( 739): #2 FlutterBoostAppState.initState. (package:flutter_boost/src/flutter_boost_app.dart:107)
[ ] I/flutter ( 739): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144)
[ ] I/flutter ( 739): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090)
[ ] I/flutter ( 739): #5 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:865)
[ ] I/flutter ( 739): #13 TickerFuture.whenCompleteOrCancel.thunk (package:flutter/src/scheduler/ticker.dart:407)
[ ] I/flutter ( 739): (elided 10 frames from class _RawReceivePortImpl, class _Timer, and dart:async)
[ ] I/flutter ( 739): AppLifecycleObserver / - onForground
[ +9 ms] I/flutter ( 739): AppLifecycleObserver - splash_page- onPagePush
[ ] I/flutter ( 739): FlutterBoost#Oops, Failed to update overlay. mode=BoostSpecificEntryRefreshMode.add, BoostContainer(name:splash_page, pages:[BoostPage(name:splash_page, uniqueId:264acaea-100f-4a3b-9828-9c667652b2e1_splash_page, arguments:{})])
[ ] I/flutter ( 739): Another exception was thrown: Instance of 'DiagnosticsProperty'

ncgqoxb0

ncgqoxb01#

麻烦提供一个可以复现的demo,谢谢

pbossiut

pbossiut2#

[ ] I/flutter ( 739): Null check operator used on a null value
[ ] I/flutter ( 739): #0 BoostChannel.addEventListener (package:flutter_boost/src/boost_channel.dart:34)

检查一下addEventListener的时机,不是不太早了,引擎还没有准备好~

4zcjmb1e

4zcjmb1e3#

看boost的源码,这种情况不应该会出现。空检查出错的入口是在FlutterBoostAppState的initState方法中:

@override
  void initState() {
    ...
    ...
    WidgetsBinding.instance!.addPostFrameCallback((_) {
      // try to restore routes from host when hot restart.
      assert(() {
        _restoreStackForHotRestart();
        return true;
      }());

      refreshOnPush(initialContainer);     //这个里面先出错
      _boostFlutterRouterApi!.isEnvReady = true;
      _addAppLifecycleStateEventListener();    //之后这里面再出错,但原因是一样
      BoostOperationQueue.instance.runPendingOperations();
    });
  }

原因是更里面的 overlayKey.currentState 为空,这个overlayKey是GlobalKey,绑定的是FlutterBoostAppState的build方法中的 Overlay 组件。
正常来说,initState中addPostFrameCallback了,build势必是在addPostFrameCallback的callback之前执行,overlayKey.currentState一定能绑上,不应该会有这种报错才对。
有没有可能是release下,你的splash_page这个页面,initState或build过程中有报错,导致element tree mount不上,所以出现这个问题?

pftdvrlh

pftdvrlh4#

[ ] I/flutter ( 739): Null check operator used on a null value
[ ] I/flutter ( 739): #0 BoostChannel.addEventListener (package:flutter_boost/src/boost_channel.dart:34)

检查一下addEventListener的时机,不是不太早了,引擎还没有准备好~

目前我将如下代码延迟执行300ms后,白屏问题处理了
FlutterBoostAppState#initState()中

@override
  void initState() {
   ...
   ...
    WidgetsBinding.instance!.addPostFrameCallback((_) {
      // try to restore routes from host when hot restart.
      assert(() {
        _restoreStackForHotRestart();
        return true;
      }());

      refreshOnPush(initialContainer);
//延迟执行
      Future.delayed(Duration(milliseconds: 300)).then((value) {
        _boostFlutterRouterApi.isEnvReady = true;
        _addAppLifecycleStateEventListener();
        BoostOperationQueue.instance.runPendingOperations();
      });
    });
  }
rkkpypqq

rkkpypqq6#

[ ] I/flutter ( 739): Null check operator used on a null value
[ ] I/flutter ( 739): #0 BoostChannel.addEventListener (package:flutter_boost/src/boost_channel.dart:34)

检查一下addEventListener的时机,不是不太早了,引擎还没有准备好~

那想要在全局addEventListener,时机是什么时候呢?
static BoostChannel get instance { _instance._appState ??= overlayKey.currentContext ?.findAncestorStateOfType<FlutterBoostAppState>(); return _instance; }
内部使用到了findAncestorStateOfType来获取FlutterBoostAppState,导致无法在initState中addEventListener,有什么解决方案吗?

nxowjjhe

nxowjjhe7#

@0xZOne https://github.com/neutronstarer/flutter_boost/tree/cfae
flutter_boost_demo项目,在原生flutter_boost会必现。这个分支是我按照 @v587jasonzou 的方式修改之后可以使用的。

72qzrwbm

72qzrwbm8#

@0xZOne https://github.com/neutronstarer/flutter_boost/tree/cfae flutter_boost_demo项目,在原生flutter_boost会必现。这个分支是我按照 @v587jasonzou 的方式修改之后可以使用的。

你的项目的flutter_boost_demo里,并没有自定义Application。FlutterBoost的接入文档里有写在MyApp中调用 FlutterBoost.instance().setup 方法进行初始化,这个方法会提前初始化FlutterEngine。

相关问题