我打算在登陆成功跳转其他页面后,没有左上角的返回箭头,要如何实现,我把其中的路由方法换成pushAndRemoveUntil也是不行,出现报错,那要怎么办
这是登陆界面
这是登陆后的页面,我希望这个左上方的返回箭头消失
以下是部分代码
登陆界面
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: "个人"
),
]),
);;
}
}