Flutter hold splash screen for 3 Seconds. How to implement splash screen in Flutter?

前端 未结 9 2027
后悔当初
后悔当初 2021-02-16 00:16

How to show splash screen in flutter for 3 seconds and then go next my login screen.

I have tried.countdowntimer but import is unresolved

import \'pack         


        
9条回答
  •  旧巷少年郎
    2021-02-16 00:35

    The cleanest approach without adding explicit timers.

    Use Time based SplashScreen.

    class TimeBasedSplash extends State{
    
      @override
      Widget build(BuildContext context) {
        return new SplashScreen(
          seconds: 10,
          navigateAfterSeconds: new HomeScreen(),// Where to navigate after 10 secs
          image: new Image.asset('assets/images/flutter_logo.png'),
          photoSize: 200,
          loaderColor: Colors.white,
          styleTextUnderTheLoader : const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold, color: Colors.white),
         loadingText: new Text('Loading...'),
          gradientBackground: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Colors.lightBlue,
              Colors.indigo
            ],
          ),
        );
      }
    
    }
    

    In main class

    void main(){
      runApp(new MaterialApp(
        home: new MyApp(),
      ));
    }
    
    
    class MyApp extends StatefulWidget {
      @override
      _MyAppState createState() => new _MyAppState();
    }
    
    class _MyAppState extends State {
      @override
      Widget build(BuildContext context) {
        return new TimeBasedSplash().build(context);
      }
    }
    

提交回复
热议问题