在dispose()之后调用Flutter-setState



我的应用程序中有一个TextFieldController,但每次我用键盘在其中键入任何内容时,我的整个应用程序都会重新加载并显示错误,

Error: setState() called after dispose(): _SlidingPanelState#65b14(lifecycle state: defunct, not mounted)

这个错误似乎与SlidingPanel有关,但我不确定它为什么会干扰TextFieldController。

SliverToBoxAdapter(
child: Container(
height: 100,
padding: const EdgeInsets.all(20.0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
labelText: 'Enter Name',
hintText: 'Enter Your Name'),
),
),
),

在_SlidingPanelState 中查找

setState(() {);

并将其更改为

if (mounted) {
setState(() {);
}

最新更新