Flutter 如何在更改BLoC模式上的小部件时添加动画过渡?

Flutter 如何在更改BLoC模式上的小部件时添加动画过渡?,flutter,flutter-animation,bloc,Flutter,Flutter Animation,Bloc,所以我跟着,虽然我设法完成了它,但我对颤振和飞镖还是相当陌生的 代码中有一部分根据状态返回不同的小部件,而不是新的支架。由于它不使用路由,页面之间的转换看起来很不稳定 返回BlocProvider( bloc:authenticationBloc, 孩子:MaterialApp( debugShowCheckedModeBanner:false, 主页:BlocBuilder( bloc:authenticationBloc, 生成器:(BuildContext上下文,Authenticatio

所以我跟着,虽然我设法完成了它,但我对颤振和飞镖还是相当陌生的

代码中有一部分根据状态返回不同的小部件,而不是新的支架。由于它不使用路由,页面之间的转换看起来很不稳定

返回BlocProvider(
bloc:authenticationBloc,
孩子:MaterialApp(
debugShowCheckedModeBanner:false,
主页:BlocBuilder(
bloc:authenticationBloc,
生成器:(BuildContext上下文,AuthenticationState){
如果(状态为AuthenticationUninitialized){
返回第页();
}
如果(状态为AuthenticationAuthenticated){
返回主页();
}
如果(状态为AuthenticationUnauthenticated){
返回登录页面(userRepository:userRepository);
}
如果(状态为AuthenticationLoading){
返回LoadingIndicator();
}
},
),
),
);
我已尝试添加一个Navigation.push包装返回,如下所示:

if(状态为AuthenticationUninitialized){
导航.推送(
返回第页();
),
}

但是,虽然这在语法上并没有错,但这会使应用程序崩溃。有人知道在维护集团示例的同时实现这一点的方法吗?谢谢。

您可以用以下内容包装页面:

要模拟导航器,请在Android中按下转换按钮,将其传递给

transitionBuilder: (Widget child, Animation<double> animation) {
  return SlideTransition(
    position: Tween<Offset>(
      begin: const Offset(0, 0.25),
      end: Offset.zero,
    ).animate(animation),
    child: child,
  );
},
transitionBuilder:(小部件子项,动画){
返回幻灯片转换(
位置:吐温(
开始:常数偏移(0,0.25),
结束:偏移0.0,
).制作动画(动画),
孩子:孩子,
);
},
要使用系统转换,请尝试以下操作

transitionBuilder: (Widget child, Animation<double> animation) {
  final theme = Theme.of(context).pageTransitionsTheme;
  final prev = MaterialPageRoute(builder: (_) => widget);
  return theme.buildTransitions(prev, context, animation, null, child);
},
transitionBuilder:(小部件子项,动画){
最终主题=theme.of(context).pageTransitionsTheme;
最终版本=MaterialPage路由(生成器:(\u)=>小部件);
返回theme.buildTransitions(prev、context、animation、null、child);
},

(最后一个测试不好)

此外,AnimatedSwitcher的子项必须有一个键来表示更改。如果您不想修改您的子小部件(它是无状态小部件或具有自己密钥的StatefulWidget),请使用容器包装它,并将容器密钥设置为:UniqueKey()。
transitionBuilder: (Widget child, Animation<double> animation) {
  return SlideTransition(
    position: Tween<Offset>(
      begin: const Offset(0, 0.25),
      end: Offset.zero,
    ).animate(animation),
    child: child,
  );
},
transitionBuilder: (Widget child, Animation<double> animation) {
  final theme = Theme.of(context).pageTransitionsTheme;
  final prev = MaterialPageRoute(builder: (_) => widget);
  return theme.buildTransitions(prev, context, animation, null, child);
},