早上好,知更鸟 2023-03-26 15:36 采纳率: 80%
浏览 37

flutter跳转路由后怎么取消左上角的返回箭头

我打算在登陆成功跳转其他页面后,没有左上角的返回箭头,要如何实现,我把其中的路由方法换成pushAndRemoveUntil也是不行,出现报错,那要怎么办

img

这是登陆界面

img

这是登陆后的页面,我希望这个左上方的返回箭头消失

img

以下是部分代码
登陆界面

class Myapp extends StatefulWidget {
  const Myapp({Key? key}) : super(key: key);

  @override
  State<Myapp> createState() => _MyappState();
}

class _MyappState extends State<Myapp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'test',
      home: Scaffold(
        body: LoginScreen(),
    ),
    );
  }
}


class LoginScreen extends StatefulWidget {
  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
  final _formKey = GlobalKey<FormState>();
  final _usernameController = TextEditingController();
  final _passwordController = TextEditingController();

  Future<void> _login() async {
    final username = _usernameController.text;
    final password = _passwordController.text;

    try {
      final response = await Dio().post(
        'http://192.168.2.7:5000/login',
        data: {'username': username, 'password': password},
      );
      if(response.statusCode==200){
        Navigator.push(context,
            MaterialPageRoute(builder: (context) {
              return const Mytab();
            }));
        Navigator.pop(context);
      }

      // handle successful login
    } catch (e) {
      // handle login failure
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Login'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Form(
          key: _formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              TextFormField(
                controller: _usernameController,
                decoration: InputDecoration(
                  labelText: 'Username',
                ),
                validator: (value) {
                  if (value!.isEmpty) {
                    return 'Please enter your username';
                  }
                  return null;
                },
              ),
              TextFormField(
                controller: _passwordController,
                decoration: InputDecoration(
                  labelText: 'Password',
                ),
                obscureText: true,
                validator: (value) {
                  if (value!.isEmpty) {
                    return 'Please enter your password';
                  }
                  return null;
                },
              ),
              SizedBox(height: 16.0),
              ElevatedButton(
                child: Text('Login'),
                onPressed: () {
                  if (_formKey.currentState!.validate()) {
                    _login();
                  }
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

void main(){
  runApp(Myapp());
}

然后是跳转有底部导航栏的页面代码

class Mytab extends StatefulWidget {
  const Mytab({Key? key}) : super(key: key);

  @override
  State<Mytab> createState() => _MytabState();
}

class _MytabState extends State<Mytab> {
  int _currentIndex=0;
  final List<Widget> _pages= [
    Myhome(),
    jijin(),
    Myperson()
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Flutter App")),
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap:(int v){
            setState((){
              _currentIndex=v;
            });
          },
          items: const [
            BottomNavigationBarItem(
                icon: Icon(Icons.home),
                label: "首页"
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.star_rounded),
                label: "我的仓库"
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.account_circle),
                label: "个人"
            ),
          ]),
    );;
  }
}


  • 写回答

2条回答 默认 最新

  • 韩曙亮 2023年度博客之星评选 TOP 1 2023-03-26 23:06
    关注

    用下面的方式 进行跳转 , 没有返回按钮 :

    Navigator.pushReplacement( context,  MaterialPageRoute( ... ));
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 3月26日

悬赏问题

  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
  • ¥15 虚拟机检测,可以是封装好的DLL,可付费
  • ¥15 kafka无法正常启动(只启动了一瞬间会然后挂了)
  • ¥30 使用matlab将观测点聚合成多条目标轨迹
  • ¥15 Workbench中材料库无法更新,如何解决?
  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 有没有整苹果智能分拣线上图像数据