标签:lis value htm demo isa state bar app 窗口
使用这个修改状态可以不用setState()。
class _MyHomeState extends State<MyHome> {
final ValueNotifier<int> _counter = ValueNotifier<int>(0);
final Widget goodJob = const Text('Good job!');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ValueListenableBuilder(
builder: (BuildContext context, int value, Widget child) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
child,
Text('$value'),
child,
],
);
},
valueListenable: _counter,
child: goodJob,
)
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.plus_one),
onPressed: () => _counter.value += 1,
),
);
}
}
Flutter: ValueListenableBuilder 内容与ValueListenable保持"同步"的窗口小部件
标签:lis value htm demo isa state bar app 窗口
原文地址:https://www.cnblogs.com/ajanuw/p/10924548.html