首先貼個官方的設置方法,看這里:https://flutterchina.club/assets-and-images/#%E6%9B%B4%E6%96%B0%E5%90%AF%E5%8A%A8%E9%A1%B5
 雖然官方的方法比較簡單,但是有時我們可能需要自己配置啟動圖的生效時間,這時就需要另外實現了。思路就是第一個頁面放一張全屏圖片,倒數計時結束時再跳轉到主頁:
1 import 'dart:async'; 2 import 'package:flutter/material.dart'; 3 import 'package:/pages/home.dart'; 4 import 'package:flutter/services.dart'; 5 6 void main() { 7 runApp(new MaterialApp( 8 title: '啟動圖demo', 9 theme: new ThemeData( 10 brightness: Brightness.light, 11 backgroundColor: Colors.white, 12 platform: TargetPlatform.iOS), 13 home: new SplashScreen(), 14 routes: <String, WidgetBuilder>{ 15 '/home': (BuildContext context) => new Home() 16 }, 17 )); 18 } 19 20 class SplashScreen extends StatefulWidget { 21 @override 22 _SplashScreenState createState() => new _SplashScreenState(); 23 } 24 25 class _SplashScreenState extends State<SplashScreen> { 26 startTime() async { 27 //設置啟動圖生效時間 28 var _duration = new Duration(seconds: 1); 29 return new Timer(_duration, navigationPage); 30 } 31 32 void navigationPage() { 33 Navigator.of(context).pushReplacementNamed('/home'); 34 } 35 36 @override 37 void initState() { 38 super.initState(); 39 startTime(); 40 } 41 42 @override 43 Widget build(BuildContext context) { 44 return new Scaffold( 45 body: new Center( 46 child: new Image.asset('assets/images/launch_image.png'), 47 ), 48 ); 49 } 50 }
最后記得將啟動圖在pubspec.yaml文件聲明下,完畢~
