flutter - 在颤动中从标签栏推送和弹出导航?
问题描述
您好,我是 Flutter 的新手,我在main.dart
点击按钮后在页面中创建了一个登录表单,logout
它将打开带有 2 个孩子的 TabbarTab1.dart
和Tab2.dart
. 在Tab2.dart
,我有注销按钮,在注销时单击我只是导航到我的登录页面,但我尝试过,它向我显示黑屏。
//main.dart
child: RaisedButton(
child: Text(
"Login",
style: TextStyle(fontSize: 20),
),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => TabBarPage()));
},
)
//Tab2.dart
class Tab2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("PROFILE"),
),
body: Center(
child: Container(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: RaisedButton(
color: Theme.of(context).accentColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Logout',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
Icon(
Icons.settings_power,
color: Colors.white,
),
],
),
onPressed: () {
Navigator.pop(context);
},
),
),
)
],
),
),
),
);
}
}
解决方案
只需main.dart
用以下代码替换您的代码
child: RaisedButton(
child: Text(
"Login",
style: TextStyle(fontSize: 20),
),
onPressed: () {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (context) => TabBarPage()))
},
)
推荐阅读
- telegram - 如何使用 Telethon 将消息转发给其他联系人
- pine-script - 我有一个在 Pine Script 中找不到的函数脚本
- laravel - laravel 干预图像源在部署时不可读
- javascript - Javascript中最长的递减子序列子数组
- c++ - 将 unsigned int 的最大值转换为 int 并期望结果为-1 是否可移植?
- node.js - node-windows权限被拒绝-编译后不请求权限?
- c++ - 如果服务器每秒发送大约 180,000 字节的数据包,我是否需要考虑使用 IOCP 服务器和航位推算?
- python - 如何在字段上定义带有类型提示的 Python 类
- flutter - Image.network 或 NetworkImage 中的图像故障
- eclipse - eclipse为什么在编辑文件之前java文件中的某些代码有背景色