标签:执行 text 设计 mep 相同 配置环境 androi 大量 center
初识flutterimport ‘package:flutter/material.dart‘;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {br/>@override
Widget build(BuildContext context) {
return MaterialApp(
title: ‘Flutter Demo‘,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: ‘Flutter Demo Home Page‘),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;br/>@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
‘You have pushed the button this many times:‘,
),
Text(
‘$_counter‘,
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: ‘Increment‘,
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
可以看到两个类MyApp和MyHomePage,从名字我们就可以看出,一个是App的入口,一个是首页,前者继承StatelessWidget,后者继承StatefulWidget,说明MyApp是不需要状态的,而MyHomePage是需要的,所以它实现了createState方法来生成一个State(不管是StatelessWidget还是StatefulWidget,本身都是不可变的),_MyHomePageState继承了State<MyHomePage>,重写了build方法,返回Scaffold,其实Scaffold中的代码就是展示在页面中的内容。最后附上flutter的架构图:
领取上图资料欢迎加入Android开发技术交流QQ群:653583088,本群可免费获取Gradle、RxJava、小程序、Hybrid、移动架构、NDK、React Native、性能优化等技术教程!
标签:执行 text 设计 mep 相同 配置环境 androi 大量 center
原文地址:http://blog.51cto.com/13983283/2335618