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{
  @override
  Widget 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>{
  @override
  Widget 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,),
    );
  }
  @override
  void initState() {
    // TODO: implement initState
    super.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{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('splash'),
        centerTitle: true,
      ),
      body: Center(
        child: Text('案例',style:Theme.of(context).textTheme.display2,),
      ),
    );
  }
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐