AnimatedSplashScreen PageTransitionType 错误

Jer*_*Zaw 6 splash-screen android-animation null-check dart flutter

我使用时遇到问题AnimatedSplashScreen,在我添加pageTransitionType. 然后我得到一个错误:

\n
\n

构建 AnimatedBuilder(animation: Listenable.merge([kAlwaysCompleteAnimation\xe2\x9e\xa9ProxyAnimation, kAlwaysDismissedAnimation\xe2\x9e\xa9ProxyAnimation]), dirty, state: _AnimatedState#bd6f7):\n在 null 上使用 Null 检查运算符时抛出以下 _CastError价值

\n
\n

这是一个产生该问题的简单应用程序:

\n
import \'package:animated_splash_screen/animated_splash_screen.dart\';\nimport \'package:flutter/material.dart\';\nimport \'package:page_transition/page_transition.dart\';\n\nvoid main() {\n  runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      home: AnimatedSplashScreen(\n        splash: Icon(Icons.person),\n        pageTransitionType: PageTransitionType.scale, //with that line commented there is no error\n        nextScreen: HomePage()\n      ),\n    );\n  }\n}\n\nclass HomePage extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return Container();\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试过运行许多命令,例如flutter pub get等。

\n

此外,依赖项pubspec.yaml运行顺利:

\n
animated_splash_screen: ^1.1.0\npage_transition: ^2.0.1-nullsafety.0\n
Run Code Online (Sandbox Code Playgroud)\n

Jer*_*Zaw 0

其实这么多年过去了,我自己已经找到了答案。

问题是,Animated Splash ScreenWidget 实际上有两个不同的参数。一个用于 Splash 动画的过渡splashTransition,一个用于下一屏幕的过渡pageTransistionType

因此,解决了所提出的问题并允许使用比例转换的简单应用程序将如下所示:

import 'package:animated_splash_screen/animated_splash_screen.dart';
import 'package:flutter/material.dart';
import 'package:page_transition/page_transition.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: AnimatedSplashScreen(
          splash: const Icon(Icons.person),
          splashTransition: SplashTransition.scaleTransition,
          pageTransitionType: PageTransitionType.fade, //with that line commented there is no error
          nextScreen: HomePage()
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
Run Code Online (Sandbox Code Playgroud)