【问题标题】:Why does application close on back button - Flutter为什么应用程序在后退按钮上关闭 - Flutter
【发布时间】:2020-05-08 15:41:08
【问题描述】:

正如我的问题所说,按下手机后退按钮应用程序将返回自定义启动屏幕而不是上一页。知道会有什么问题吗?以下是 main.dart 代码

void main() => runApp(new MaterialApp(
    theme: ThemeData(primaryColor: Colors.red),
    debugShowCheckedModeBanner: false,
    home: SplashScreen(),
    ))

启动画面在 3 秒后关闭,应用程序进入登录页面。

提前致谢。

【问题讨论】:

  • 显示您的 SplashScreen 页面代码
  • 3秒后进入登录页面@override void initState() { // TODO: implement initState super.initState(); Timer( Duration(seconds: 3), () => Navigator.push( context, MaterialPageRoute( builder: (context) => LoginApp()))); }
  • @AR 我添加了闪屏页面代码。
  • 你到底想做什么,你想直接从登录屏幕关闭应用程序吗?

标签: android flutter dart flutter-navigation


【解决方案1】:

可能你错误​​地使用了导航器,使用pushReplacementSplashScreen 替换为新的。并使用push 在上一个屏幕上打开一个新屏幕。

示例:

// Close splash screen and open MainPage
Navigator.of(context).pushReplacement(MainPage.route());

// Open LoginPage on top of the previous page
Navigator.of(context).push(LoginPage.route());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 2020-01-12
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多