问题描述
我收到一个错误,提示_lifecycleState!= _ElementLifecycle.defunct':不正确.
我不确定为什么会引发错误,但是我的代码在这里
class MyprofilTile扩展了StatefulWidget {最终的TextEditingController搜索输入;const MyprofilTile({Key key,this.searchinginput}):super(key:key);@override_MyprofilTileState createState()=>_MyprofilTileState();}类_MyprofilTileState扩展了State< MyprofilTile>{列出_allResults = [];清单_resultsList = [];未来结果已加载;_onsearchChanged(){此lineeeeeeeeeeeeeeeeeeeeeeeeeee搜索结果();//print(args.searchcontroller);}搜索结果(){var showResults = [];if(widget.searchinginput.text!=")){for(_allResults中的var tripsnapshot){var title = DatbaseService.instance.userDataFromSnapshot(tripsnapshot).username.toLowerCase();if(title.contains(widget.searchinginput.text.toLowerCase())){showResults.add(tripsnapshot);}}}别的{showResults = List.from(_allResults);}setState((){.其this lineeeeeeeeeeeeeeeeeee_resultsList = showResults;});}@override无效的initState(){super.initState();widget.searchinginput.addListener(_onsearchChanged);和此lineeeeeeeeeeeee}@override无效dispose(){widget.searchinginput.removeListener(_onsearchChanged());widget.searchinginput.dispose();super.dispose();}@overridevoid didChangeDependencies(){super.didChangeDependencies();resultsLoaded = getusers();}getusers()异步{var firestore = FirebaseFirestore.instance;QuerySnapshot qn =等待firestore.collection('meinprofilsettings').get();setState((){_allResults = qn.docs;});搜索结果();返回完成";}
这是错误
我正在使用此statefulwidget内文本字段中的controller值.如果您需要更多信息,请发表评论
我不确定您要在这里实现什么,但是无法神奇地"在另一个小部件中访问一个小部件中的变量./p>
这里的错误是您试图调用从未初始化的 args
上的 searchcontroller
.请记住,创建一个作为Widget的变量是行不通的,并且您不必这样做.
Im getting an error that says _lifecycleState != _ElementLifecycle.defunct': is not true.
im not sure why the error throws but heres my code
class MyprofilTile extends StatefulWidget {
final TextEditingController searchinginput;
const MyprofilTile ({ Key key, this.searchinginput }): super(key: key);
@override
_MyprofilTileState createState() => _MyprofilTileState();
}
class _MyprofilTileState extends State<MyprofilTile> {
List _allResults=[];
List _resultsList=[];
Future resultsLoaded;
_onsearchChanged(){this lineeeeeeeeeeeeeeeeeeeeeeeee
searchResults();
// print(args.searchcontroller);
}
searchResults(){
var showResults=[];
if(widget.searchinginput.text!=""){
for(var tripsnapshot in _allResults){
var title = DatbaseService.instance.userDataFromSnapshot(tripsnapshot).username.toLowerCase();
if(title.contains(widget.searchinginput.text.toLowerCase())){
showResults.add(tripsnapshot);
}
}
}
else{
showResults=List.from(_allResults);
}
setState(() {. its this lineeeeeeeeeeeeeeeee
_resultsList = showResults;
});
}
@override
void initState(){
super.initState();
widget.searchinginput.addListener(_onsearchChanged);and this lineeeeeeeeeeeee
}
@override
void dispose(){
widget.searchinginput.removeListener(_onsearchChanged());
widget.searchinginput.dispose();
super.dispose();
}
@override
void didChangeDependencies(){
super.didChangeDependencies();
resultsLoaded = getusers();
}
getusers() async {
var firestore = FirebaseFirestore.instance;
QuerySnapshot qn = await firestore.collection('meinprofilsettings').get();
setState(() {
_allResults =qn.docs;
});
searchResults();
return "Complete";
}
This is the error
Im using the value of controller from a textfield inside this statefulwidget .If you need more information please leave a comment
I'm not sure what you're trying to achieve here, but a variable in a widget can't be accessed in another widget 'magically'.
Your error here is that you're trying to call searchcontroller
on args
which was never initialised. Keep in mind that creating a variable which is a Widget won't work, and you shouldn't have to do it.
这篇关于断言失败:行4109位置12:'_lifecycleState!= _ElementLifecycle.defunct':不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!