本文的核心内容包括:
我们接触的每一个Flutter界面,大多由布局和逻辑相关的代码组成。如Flutter初始工程的Counting Demo的代码:
class _MyHomePageState extends State {
// 变量
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: [
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter', // 变量使用
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: Floa