1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import 'package:flutter/material.dart';//引入包 //main.dart 程序第一个类 类似于android的MyApplication 系统默认入口 可通过studio自定义配置 //void main 当前页面的主入口类似于android中的onStart void main() => runApp(MyApp()); //Stateless widgets 是不可变的, 这意味着它们的属性不能改变 - 所有的值都是最终的,适用于方法内部不会动态改变的时候使用. //Stateful widgets 持有的状态可能在widget生命周期中发生变化,适用于方法内部需要动态改变的时候使用. class MyApp extends StatelessWidget{ @override Widget build(BuildContext context) { // TODO: implement build return new MaterialApp( title:'flutter demo',//程序切换到后台时显示的标题 home: _home(),//程序主体 ); } } class _home extends StatefulWidget{ @override State<StatefulWidget> createState() { return _homeState(); } } class _homeState extends State<_home>{ @override Widget build(BuildContext context) { // TODO: implement build return new Scaffold( //Scaffold 实现了基本的纸墨设计布局结构。可参考:https://www.jianshu.com/p/a08f43173b72 appBar: new AppBar(//标题栏 title: Text("title"),//标题 centerTitle: true,//标题居中 ), body: new Center(//body 页面布局 Center内的内容页面居中 child: new Text("hello word"),//child 子控件 ) ); } }
|