import 'package:flutter/material.dart';
void main() {
/**
* runApp函数将根控件显示在屏幕上
*/
runApp(new MaterialApp(
title: "我的应用",
// 使用主题更改Ui
theme: new ThemeData(
primaryColor: Colors.white,
),
home: new MyScaffold(),
));
}
class MyScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
/**
* Scaffold 是 Material library 中提供的一个widget,
* 它提供了默认的导航栏、标题和包含主屏幕widget树的body属性。
* widget树可以很复杂
*/
return new Material(
child: new Scaffold(
appBar: new AppBar(
title: new Text("hello flutter",
style: Theme.of(context).primaryTextTheme.title),
),
//Center控件使其子控件在中间位置
body: new Center(
// Text控件显示各种文本
child: new Text("hello flutter"),
)),
);
}
}
StatelessWidget是什么?
前面已经说过Flutter中大多数东西都是widget,StatelessWidget是widget的子类,他代表的是一类无状态的widget,
还有另一个对应的有状态的statefulWidget
Widget的两大分类,两者的差距在于你是否需要管理控件的状态
statelessWidget:无状态的
statefulWidget”:有状态的(如果用户和widget交互,widget会发生变化,他就是有状态的)