Flutter导航器推送过渡未显示

时间:2020-08-22 07:03:06

标签: flutter firebase-authentication splash-screen flutter-animation flutter-navigation

一旦尝试处理Firebase身份验证用户,我将尝试制作一个具有淡入淡出动画的初始屏幕。这是我目前的代码:

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  void initState() {
    auth.onAuthStateChanged.listen((user) async {
      if (user == null) {
        if (ModalRoute.of(context).isCurrent) {
          Navigator.pushNamed(context, '/welcome');
        } else {
          Navigator.popUntil(context, ModalRoute.withName('/welcome'));
        }
      } else {
        Navigator.of(context).push(
          PageRouteBuilder(
            pageBuilder: (BuildContext context, Animation<double> animation1, Animation<double> animation2) {
              return NavigationHomeScreen();
            },
            transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> animation2, Widget child) {
              return FadeTransition(
                opacity: animation,
                child: child
              );
            },
          ),
        );
      }
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Image.asset(
          'assets/icons/app_logo_transparent.png',
          width: MediaQuery.of(context).size.width*0.4,
        ),
      ),
    );
  }
}

由于某种原因,动画从不显示,并且屏幕仅从启动屏幕突然切换到主屏幕。我已经验证了此动画可以在所有其他实例中使用,但是在此listen方法中却不起作用。另外,如果我从主屏幕弹出回到初始屏幕,则动画效果很好。当我按到主屏幕时,它只是不显示。有人知道如何解决这个问题吗?

0 个答案:

没有答案