firebase - 如何使用提供程序为登录屏幕过渡设置动画?
问题描述
当 Firebase 身份验证状态更改为provider
.
但是屏幕变化没有动画。我已经尝试使用Navigator.of(context).pushReplacementNamed
,但这会导致很多错误。
模型中的状态更改时如何为自动屏幕更改设置动画?(我看过,但没有教程涵盖这个。所有的屏幕变化都没有动画)。
感谢帮助!
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
builder: (_) => UserRepository.instance(),
child: Consumer(
builder: (context, UserRepository user, _) {
switch (user.status) {
case Status.Uninitialized:
return Splash();
case Status.Unauthenticated:
case Status.Authenticating:
return LoginPage();
case Status.Authenticated:
return UserInfoPage(user: user.user);
}
},
),
);
}
}
解决方案
这是我认为 Rémi Rousselet 的建议的代码示例。只要身份验证状态发生变化,Provider.of(...)
调用就会触发重建,当前屏幕在 switch 语句中设置,并AnimatedSwitcher
使用 aFadeTransition
从前一个屏幕动画到当前屏幕。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var authenticationService = Provider.of<AuthenticationService>(context);
Widget _currentScreen;
switch (authenticationService.status) {
case AuthenticationStatus.authenticated:
_currentScreen = MainScreen();
break;
case AuthenticationStatus.uninitialized:
_currentScreen = SplashScreen();
break;
case AuthenticationStatus.authenticating:
_currentScreen = LoadingScreen();
break;
case AuthenticationStatus.unauthenticated:
default:
_currentScreen = SignInScreen();
}
return MaterialApp(
title: 'My App',
home: AnimatedSwitcher(
duration: Duration(milliseconds: 500),
child: _currentScreen,
),
);
}
}
推荐阅读
- typo3 - 错字3 8.7.x tx_news 7.0.5 用新闻标题覆盖默认元标记标题
- ios - 如何在选择 tableView 的行单元格时显示视图控制器(作为集合视图单元格)?
- php - Wordpress 按标签过滤帖子
- mongodb - MongoDB将两个数组内的值相乘
- linux - 为什么 NOP 的数量似乎会影响 shellcode 是否成功执行?
- android - 在加载活动期间将嵌套滚动视图的顶部设置为总高度的一半时遇到问题
- java - 用 Regex 替换 Java 中的空格和分号
- javascript - 数据存在于剪贴板中,但我无法在 JavaScript 中获取它
- java - Spring中构造函数参数的歧义
- html - flexbox子元素内部div的高度