从页面返回时,Flutter导航显示了一个黑色404屏幕
我正在flutter中的导航器面对这个问题,当我从页面返回时,我会重定向到黑色404页。
这是导航流:
- 登录后登录屏幕
- 主页屏幕
,我被重定向到主页,我应该无法返回到以前的屏幕,但是如果我向右滑动,我会显示一个黑页面带有404标签,我不能从那里移动。预先感谢您的任何帮助!
在这里,我提供一些代码:
class SignInPage extends StatelessWidget {
static const routeName = '/signIn';
const SignInPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Stack(
children: [
const Positioned(
left: -20,
top: -20,
child: AnimatedCircle(color: AppColors.lightBlue),
),
const Positioned(
right: -50, top: 150, child: AnimatedCircle(color: AppColors.lightOrange)),
const Positioned(
bottom: 60, left: -70, child: AnimatedCircle(color: AppColors.lightGreen)),
const Positioned(
right: -50, bottom: -60, child: AnimatedCircle(color: AppColors.lightRed)),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/logo.png'),
Container(
width: MediaQuery.of(context).size.width * 8,
margin: const EdgeInsets.symmetric(horizontal: Dimens.SPACING_XL),
child: StyledButton.outlined(
title: 'Sign in with Google',
leading: Image.asset('assets/images/google.png', scale: 30),
onPressed: () async {
final res = await Authentication.signInWithGoogle();
await Authentication.userSetup(res.user!);
Navigator.of(context).popAndPushNamed(HomePage.routeName);
},
),
),
],
),
],
),
),
],
),
);
}
}
class HomePage extends StatelessWidget {
static const routeName = '/homepage';
static const _padding = EdgeInsets.symmetric(horizontal: 20.0, vertical: 6.0);
static const _dividerOptions = 30.0;
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => ItemsProvider(),
child: Consumer<ItemsProvider>(
builder: (_, provider, __) => Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
automaticallyImplyLeading: false,
actions: [
IconButton(
onPressed: () => Navigator.of(context).pushNamed('/user'),
icon: const Icon(Icons.person)),
],
),
floatingActionButton: Visibility(
visible: provider.buttonVisibility,
child: FloatingActionButton(
heroTag: "btn1",
backgroundColor: AppColors.red,
child: const Icon(Icons.add, color: AppColors.splashColor),
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => buildModal(context, provider),
);
}),
),
body: Padding(
padding: _padding,
child: Column(
children: [
TopCard(
itemCount: provider.itemsCount,
onPressed: () {
provider.deleteAllItem();
Navigator.of(context).pop();
},
),
const Divider(
height: _dividerOptions,
thickness: 1.0,
indent: _dividerOptions,
endIndent: _dividerOptions,
),
const Expanded(
child: ItemsList(),
),
],
),
),
),
),
);
}
SingleChildScrollView buildModal(
BuildContext context,
ItemsProvider provider,
) {
return SingleChildScrollView(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
decoration: const BoxDecoration(),
child: AddItemScreen(args: AddItemScreenArguments(provider.addItem)),
),
);
}
}
I'm facing this issue with Navigator in Flutter where when I go back from a page I get redirected to a black 404 page.
This is the navigation flow:
- Login screen
- HomePage screen
After being logged in, I am redirected to the Homepage and I shouldn't be able to go back to a previous screen, but if I swipe to the right I'm shown a black page with a 404 label and I can't move from there. Thank you in advance for any help!
Here I provide some code:
class SignInPage extends StatelessWidget {
static const routeName = '/signIn';
const SignInPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Stack(
children: [
const Positioned(
left: -20,
top: -20,
child: AnimatedCircle(color: AppColors.lightBlue),
),
const Positioned(
right: -50, top: 150, child: AnimatedCircle(color: AppColors.lightOrange)),
const Positioned(
bottom: 60, left: -70, child: AnimatedCircle(color: AppColors.lightGreen)),
const Positioned(
right: -50, bottom: -60, child: AnimatedCircle(color: AppColors.lightRed)),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/logo.png'),
Container(
width: MediaQuery.of(context).size.width * 8,
margin: const EdgeInsets.symmetric(horizontal: Dimens.SPACING_XL),
child: StyledButton.outlined(
title: 'Sign in with Google',
leading: Image.asset('assets/images/google.png', scale: 30),
onPressed: () async {
final res = await Authentication.signInWithGoogle();
await Authentication.userSetup(res.user!);
Navigator.of(context).popAndPushNamed(HomePage.routeName);
},
),
),
],
),
],
),
),
],
),
);
}
}
class HomePage extends StatelessWidget {
static const routeName = '/homepage';
static const _padding = EdgeInsets.symmetric(horizontal: 20.0, vertical: 6.0);
static const _dividerOptions = 30.0;
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => ItemsProvider(),
child: Consumer<ItemsProvider>(
builder: (_, provider, __) => Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
automaticallyImplyLeading: false,
actions: [
IconButton(
onPressed: () => Navigator.of(context).pushNamed('/user'),
icon: const Icon(Icons.person)),
],
),
floatingActionButton: Visibility(
visible: provider.buttonVisibility,
child: FloatingActionButton(
heroTag: "btn1",
backgroundColor: AppColors.red,
child: const Icon(Icons.add, color: AppColors.splashColor),
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => buildModal(context, provider),
);
}),
),
body: Padding(
padding: _padding,
child: Column(
children: [
TopCard(
itemCount: provider.itemsCount,
onPressed: () {
provider.deleteAllItem();
Navigator.of(context).pop();
},
),
const Divider(
height: _dividerOptions,
thickness: 1.0,
indent: _dividerOptions,
endIndent: _dividerOptions,
),
const Expanded(
child: ItemsList(),
),
],
),
),
),
),
);
}
SingleChildScrollView buildModal(
BuildContext context,
ItemsProvider provider,
) {
return SingleChildScrollView(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
decoration: const BoxDecoration(),
child: AddItemScreen(args: AddItemScreenArguments(provider.addItem)),
),
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论