
MaterialApp应该是所有小部件的父级(根)。
import 'package:flutter/material.dart';import 'package:bmi/HomePage.dart';import 'dart:async';main() { runApp(MyApp());}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp(home: SplashScreen()); // define it once at root level. }}class SplashScreen extends StatefulWidget { @override State<StatefulWidget> createState() { return SplashScreenState(); }}class SplashScreenState extends State<SplashScreen> { @override void initState() { super.initState(); Future.delayed(Duration(seconds: 4), () { Navigator.push( context, MaterialPageRoute( builder: (context) => HomePage(), )); }); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.red, body: Text( 'Welcome to BMI Calculator', style: new TextStyle( fontSize: 15.0, color: Colors.white, fontWeight: FontWeight.bold), ), ); }}class HomePage extends StatelessWidget{ @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.red, title: Text( 'BMI Calculator', style: new TextStyle( color: Colors.white ), ), ), ); }}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)