Cod*_*ard 5 flutter flutter-widget
我有一个自定义的无状态小部件,它有一个ValueNotifier参数作为构造函数参数。
请参阅下面的片段。
\n\nclass MyWidget extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n return FlatChoiceChipList(\n choiceList: ["first item","second item","third item"],\n selectedIndex: ValueNotifier<int>(0),\n onSelected: (index) {},\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\x8b
\n\n好吧,正如您在上面的代码片段中看到的,在构建方法中我创建了一个 ValueNotifier 对象,并且稍后不会将其释放。
\n\n小智 0
1.如果你愿意的话可以,但是为什么不在FlatChoiceChipList小部件中声明它呢?
2.只有添加听众我才相信。这是处置方法:
@mustCallSuper
void dispose() {
assert(_debugAssertNotDisposed());
_listeners = null;
}
Run Code Online (Sandbox Code Playgroud)
但当您不再需要它时,最好将其丢弃。
| 归档时间: |
|
| 查看次数: |
2039 次 |
| 最近记录: |