clean-code-dev / animated_splash_screen

The easiest way to create your animated splash screen in a fully customizable way.
MIT License
112 stars 25 forks source link

[BUG] Improve startup times #30

Open henry2man opened 3 years ago

henry2man commented 3 years ago

I've been struggling with too much elevated startup times. I was using AnimatedSplashScreen.withScreenFunction in order to initialize app resources, connections...

After some researching I've found that current implementation is serializing the execution of the animation and then the execution of screenFunction.

I've imported the source code into my project and I've improved startup times using Future.wait[...<futures>...].

Please take a look of this snippet of _AnimatedSplashScreenState (full implementation can be found here https://gist.github.com/henry2man/0658f657f2087caac2cd579b783981d4)

PS: I've also considered that "function" attribute is a always pure function that doesn't return any Widget, so I use always "nextScreen" attribute

PS2: Also I think that a default duration of 2500 milliseconds is too much. Please consider change this to 1000ms, as per Miller, Card et al,

@override
  void initState() {
    super.initState();

    _animationController = new AnimationController(
        duration: w.animationDuration ?? Duration(milliseconds: 800),
        vsync: this);
    [...]
    _animation = animation
        .animate(CurvedAnimation(parent: _animationController, curve: w.curve));

    // Parallelize both animation & async startup function
    Future.wait([
      _animationController.forward(),
      if (w.function != null) w.function!()
    ]).then((value) => doTransition());
  }

  /// jump to next screen
  doTransition() {
    if (!w.disableNavigation) navigator(w.nextScreen);
  }