您可以使用AnimatedSwitcher包装页面:
return BlocProvider<AuthenticationBloc>( bloc: authenticationBloc, child: MaterialApp( home: BlocBuilder<AuthenticationEvent, AuthenticationState>( bloc: authenticationBloc, builder: (BuildContext context, AuthState state) { return AnimatedSwitcher( duration: Duration(milliseconds: 250), child: _buildPage(context, state), ); }, ), ),);
默认情况下,它使用淡入淡出过渡,并以相反的顺序为旧的和新的小部件设置动画。
要在动画过程中将旧窗口小部件保留在适当的位置,请传递给AnimatedSwitcher
switchOutCurve: Threshold(0),
要模拟
Navigator.pushAndroid中的过渡,请将其传递给它
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);},
(最后一个测试得不好)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)