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

前端 未结 9 2174
后悔当初
后悔当初 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:31

    Simple solution which i use in every app.

    Use Timer class in build method code snippet

    class SplashScreen extends StatefulWidget {
      @override
      Splash createState() => Splash();
    }
    
    class Splash extends State  {
    
      @override
      void initState() {
        super.initState();
    
      }
      @override
      Widget build(BuildContext context) {
            Timer(
                Duration(seconds: 3),
                    () =>
                Navigator.of(context).pushReplacement(MaterialPageRoute(
                    builder: (BuildContext context) => LandingScreen())));
    
    
        var assetsImage = new AssetImage(
            'images/new_logo.png'); //<- Creates an object that fetches an image.
        var image = new Image(
            image: assetsImage,
            height:300); //<- Creates a widget that displays an image.
    
        return MaterialApp(
          home: Scaffold(
            /* appBar: AppBar(
              title: Text("MyApp"),
              backgroundColor:
                  Colors.blue, //<- background color to combine with the picture :-)
            ),*/
            body: Container(
              decoration: new BoxDecoration(color: Colors.white),
              child: new Center(
                child: image,
              ),
            ), //<- place where the image appears
          ),
        );
      }
    }
    

提交回复
热议问题