我正在试着找出我需要处理的东西。因为当我使用它时,我得到了一个错误。
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4109 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true.所以这就是为什么我会问,我需要它来做一些特别的事情吗?当我从一个页面导航到另一个页面,然后再导航到另一个页面,然后又回到第一个页面时,我得到了这个错误。我的错误是在一个文本字段中,它来自文本字段,在调用dispose方法中的super值之前,我正在处理我的texeditingcontroller。但问题是,我在一个页面中调用textediting控制器,然后在另一个页面中使用此值,并将其设置为final。当我在第二页部署控制器时,我得到了这个错误。所以我需要这个吗??
这是我在这个AllFollowersearch中的代码,我声明了它,并将值设置为TextFormField
class AllFollowersearch extends StatefulWidget {
static const route = '/Followersearch';
final String receverid;
const AllFollowersearch({Key key, this.receverid}) : super(key: key);
@override
_AllFollowersearchState createState() => _AllFollowersearchState();
}
class _AllFollowersearchState extends State<AllFollowersearch> {
final searchcontroller = new TextEditingController();
child: TextField(
controller: searchcontroller,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.search,
color: Colors.black,
),
border: InputBorder.none,
hintText: "search...",
),
onTap: () {
setState(() {
isSearching = true;
});
}),
isSearching
? Expanded(
child: Openallfollower(
receiverid: widget.receverid,
searchinginput: searchcontroller,
))在这个类中,我使用TextEditingController控制器的值,并在
class Openallfollower extends StatefulWidget {
final TextEditingController searchinginput;
static const route = '/allfollower';
final String receiverid;
const Openallfollower({Key key, this.receiverid,this.searchinginput}) : super(key: key);
@override
_OpenallfollowerState createState() => _OpenallfollowerState();
}
@override
void didUpdateWidget(covariant Openallfollower oldWidget) {
// TODO: implement didUpdateWidget
super.didUpdateWidget(oldWidget);
}发布于 2021-04-07 05:32:20
当您处理textEditingController时,不要将其设为最终的,并在didUpdateWidget中重新初始化tectEditingController以再次使用
https://stackoverflow.com/questions/66976544
复制相似问题