当前位置: 代码迷 >> 综合 >> 入门到放弃(二)flutter 四步教你搞定启动页启动页
  详细解决方案

入门到放弃(二)flutter 四步教你搞定启动页启动页

热度:159   发布时间:2023-09-14 17:25:23.0

1、mian.dart

import 'package:flutter/material.dart';
import 'package:jifeng/my_app.dart';
import './my_app.dart';void main() => runApp(MyApp());

2、my_app.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jifeng/splash/splash_screen.dart';import 'home/index_page.dart';class MyApp extends StatelessWidget{@overrideWidget build(BuildContext context){return MaterialApp(title: 'loins',theme: ThemeData(primaryColor: Colors.black,),home: SplashScreen(),routes: <String,WidgetBuilder>{'/IndexPage':(context) => IndexPage()},);}
}

3、splash_screen.dart

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'dart:async';
class SplashScreen extends StatefulWidget {@override_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen>{@overrideWidget build(BuildContext context){return Container(color: Colors.white,child: Image.network('http://img.zcool.cn/community/01a99d5542ea730000019ae9cf7739.jpg@1280w_1l_2o_100sh.png',fit: BoxFit.cover,),);}@overridevoid initState() {// TODO: implement initStatesuper.initState();countDown();}void countDown(){var _duration = Duration(seconds: 4);Future.delayed(_duration,_indexPage);}void _indexPage(){Navigator.of(context).pushReplacementNamed('/IndexPage');}
}

4、index_page.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';class IndexPage extends StatelessWidget{@overrideWidget build(BuildContext context) {// TODO: implement buildreturn Scaffold(appBar: AppBar(title: Text('splash'),centerTitle: true,),body: Center(child: Text('案例',style:Theme.of(context).textTheme.display2,),),);}
}
  相关解决方案