我有一个特定类型的观察者,当我用@action函数更改这个对象的某些属性时,我的列表不会改变,如果我返回到屏幕并再次进入列表的屏幕,它就会发生变化。
这些变化是否会发生在屏幕上?
发布于 2022-10-14 23:19:12
您可能没有将页面代码放入Observer
小部件中。
https://pub.dev/documentation/flutter_mobx/latest/flutter_mobx/Observer-class.html
class CounterExample extends StatefulWidget {
const CounterExample({Key key}) : super(key: key);
@override
_CounterExampleState createState() => _CounterExampleState();
}
class _CounterExampleState extends State<CounterExample> {
final _counter = Counter();
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Counter'),
),
body: Center(
child: Observer(
builder: (_) => Text(
'${_counter.value}',
style: const TextStyle(fontSize: 20),
)),
),
floatingActionButton: FloatingActionButton(
onPressed: _counter.increment,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
https://stackoverflow.com/questions/74073823
复制相似问题