按下后退按钮并重新打开应用程序后,Flutter 卡在启动屏幕上

时间:2021-03-08 05:18:32

标签: flutter splash-screen freeze

我是 flutter 初学者,我尝试使用 launch_background.xml 实现启动画面,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ceb_launcher" />
    </item> -->
</layer-list>

启动画面工作正常。当我在主屏幕(如果登录成功,可以是登录屏幕或另一个屏幕)并且我按下后退按钮时,应用程序最小化(进入分离状态),当我重新打开应用程序时,它会卡在飞溅状态屏幕。如果我关闭应用程序并再次打开它,启动画面会出现几秒钟,然后我会转到主页。

当按下后退按钮时,调试控制台上没有显示错误:

E/libEGL  (28992): call to OpenGL ES API with no current context (logged once per thread)

当我返回时,应用程序卡在启动屏幕上:

D/EGL_emulation(28992): eglCreateContext: 0xe3b654c0: maj 2 min 0 rcv 2
D/EGL_emulation(28992): eglCreateContext: 0xe3b65520: maj 2 min 0 rcv 2
D/        (28992): HostConnection::get() New Host Connection established 0xdb871800, tid 29168
D/EGL_emulation(28992): eglMakeCurrent: 0xe3b65520: ver 2 0 (tinfo 0xdb816c30)
D/        (28992): HostConnection::get() New Host Connection established 0xdb899640, tid 29167
D/EGL_emulation(28992): eglMakeCurrent: 0xe3b654c0: ver 2 0 (tinfo 0xdb883bb0)
D/EGL_emulation(28992): eglCreateContext: 0xdb885060: maj 2 min 0 rcv 2
D/EGL_emulation(28992): eglMakeCurrent: 0xdb885060: ver 2 0 (tinfo 0xdb883bb0)
D/EGL_emulation(28992): eglMakeCurrent: 0xe3b654c0: ver 2 0 (tinfo 0xdb883bb0)
D/EGL_emulation(28992): eglMakeCurrent: 0xdb885f60: ver 2 0 (tinfo 0xc9596880)

这是我的一段代码:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(AppWidget());
}


class AppWidget extends StatelessWidget {

  @override
  Widget build(BuildContext context){

    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

    return MultiProvider(
      providers: [
        ChangeNotifierProvider.value(value: AuthenticationBLOC(),),
        ChangeNotifierProvider.value(value: EquipmentBLOC()),
        ChangeNotifierProvider.value(value: ScreenDrawerBLOC()),
      ],
      child:Consumer<AuthenticationBLOC>(builder: (ctx, autentication, _) => MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: themeAllApp(),
        home: isAuthenticated(autentication),
        onGenerateRoute: routesApp(context)
        ),
      ),
    );
  }
}


Widget isAuthenticated(AuthenticationBLOC autentication){
  if(autentication.authenticated != true){
    return FutureBuilder(
      future: autentication.tryAutoLogIn(),
      builder: (context, snapshot) => snapshot.connectionState == ConnectionState.waiting ? 
        LoadingScreenWidget() : LogInScreenWidget(),
    );
  }else{
    return Consumer<ScreenDrawerBLOC>(
      builder: (context, screen, _) => screen.isTypeScreen ? TypeDeviceScreenWidget() : 
        ContactScreenWidget(),
    );
  }
}

我已经运行了 flutter flutter doctor 并且一切正常。

如果有人对正在发生的事情有任何想法,我将不胜感激。

0 个答案:

没有答案