Search code examples
flutterdartandroid-animationsplash-screennull-check

AnimatedSplashScreen PageTransitionType error


I have a problem using AnimatedSplashScreen, everything works fine to the moment I add a pageTransitionType. Then I get an error:

The following _CastError was thrown building AnimatedBuilder(animation: Listenable.merge([kAlwaysCompleteAnimation➩ProxyAnimation, kAlwaysDismissedAnimation➩ProxyAnimation]), dirty, state: _AnimatedState#bd6f7): Null check operator used on a null value

This is a simple app which generates that problem:

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: Icon(Icons.person),
        pageTransitionType: PageTransitionType.scale, //with that line commented there is no error
        nextScreen: HomePage()
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

I have tried running many commands like flutter pub get etc.

Also, dependencies in pubspec.yaml are running smoothly:

animated_splash_screen: ^1.1.0
page_transition: ^2.0.1-nullsafety.0

Solution

  • Actually after all these years, I have found the answer myself.

    The problem was, that the Animated Splash Screen Widget actually has two different parameters. One for the transition of the Splash animation splashTransition, and one for the next screen transition pageTransistionType.

    So The simple app, that solved the question asked and allows for using a scale transition would look like this:

    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();
      }
    }