Logo
Section 1 / 3

什么是状态管理?

学习有状态组件与 Flutter 状态管理技术之间的差异及局限性。

导入

什么是状态管理?

学习有状态组件与 Flutter 状态管理技术之间的差异及局限性。

...
Flutter widget hierarchy example
...
How state moves in the widget tree using stateful widgets
1class _MyHomePageState extends State<MyHomePage> { 2 int _counter = 0; 3 4 void _incrementCounter() { 5 setState(() { 6 _counter++; 7 }); 8 } 9 10 11 Widget build(BuildContext context) { 12 return Scaffold( 13 appBar: AppBar( 14 title: Text(widget.title), 15 ), 16 body: Center( 17 child: Column( 18 mainAxisAlignment: MainAxisAlignment.center, 19 children: <Widget>[ 20 const Text( 21 'You have pushed the button this many times:', 22 ), 23 Text( 24 '$_counter', 25 style: Theme.of(context).textTheme.headline4, 26 ), 27 ], 28 ), 29 ), 30 floatingActionButton: FloatingActionButton( 31 onPressed: _incrementCounter, 32 tooltip: 'Increment', 33 child: const Icon(Icons.add), 34 ), 35 ); 36 } 37}
...
Placement of logic components in state management techniques

入门

BLoC 模式