【发布时间】:2021-07-10 13:24:04
【问题描述】:
我想在 page1 显示时显示 SnackBar。当用户从 page2 导航到 page1 时。
但我只能从 page1 工作到 page2
这是我的代码
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(
' Homepage',
),
),
body: Center(
child: RaisedButton(
***onPressed: () {
Navigator.push(context,
BouncyPageRoute3(widget: Page2()));
}***
child: Text('go to Page2'),
),
)));
}
}
class BouncyPageRoute3 extends PageRouteBuilder {
final Widget widget;
BouncyPageRoute3({this.widget})
: super(
transitionDuration: Duration(milliseconds: 700),
transitionsBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child) {
animation =
CurvedAnimation(parent: animation, curve: Curves.ease);
return ScaleTransition(
scale: animation,
alignment: Alignment.center,
child: child,
);
},
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return widget;
});
}
当您使用 Page2 上的 RaisedButton 返回主页时,我希望主页上的 SnackBar 显示
我还使用了 BouncyPageRoute3,它是用于动画的。
【问题讨论】:
-
从page1到page2的代码可以分享一下吗?
-
我将代码添加到问题@BabC