英文:
Undefined name 'duplicateItems'. Try correcting the name to one that is defined, or defining the name
问题
未定义名称'duplicateItems'。
尝试更正名称为已定义的名称,或定义该名称。
我已将其更正为另一个名称,仍然遇到相同的问题。
class view_problem extends StatefulWidget {
@override
State<view_problem> createState() => _view_problemState();
}
class _view_problemState extends State<view_problem> {
List<problemModel> problemlist = [];
StreamController _streamController = StreamController();
Future getAllProblem() async {
problemlist = await problemcontrollers().getProblem();
_streamController.sink.add(problemlist);
}
@override
void initState() {
// TODO: implement initState
Timer.periodic(Duration(seconds: 1), (timer) {
getAllProblem();
});
super.initState();
}
void _filterSearch(String query) {
setState(() {
problemlist = duplicateItems
.where((item) => item.toLowerCase().contains(query.toLowerCase()))
.toList();
});
}
}
英文:
Undefined name 'duplicateItems'.
Try correcting the name to one that is defined, or defining the name.
I have fixed it to another one still stuck with the same problem.
class view_problem extends StatefulWidget {
@override
State<view_problem> createState() => _view_problemState();
}
class _view_problemState extends State<view_problem> {
List<problemModel> problemlist = [];
StreamController _streamController = StreamController();
Future getAllProblem() async {
problemlist = await problemcontrollers().getProblem();
_streamController.sink.add(problemlist);
}
@override
void initState() {
// TODO: implement initState
Timer.periodic(Duration(seconds: 1), (timer) {
getAllProblem();
});
super.initState();
}
void _filterSearch(String query) {
setState(() {
problemlist = duplicateItems
.where((item) => item.toLowerCase().contains(query.toLowerCase()))
.toList();
});
}
答案1
得分: 0
你没有在你的函数或全局变量中定义duplicateItems。在使用之前,你必须先定义它。无论duplicateItems是一个字符串、整数还是其他类型的代码都不知道,所以我们必须明确定义它。在你的情况下,我猜它是一个字符串列表,因为它是一个搜索函数,所以我的答案是相应的。
更新的答案:在这里,我还进行了一项更改,以便在搜索查询中有空格时,它仍然会给你一个有效的结果,如果这有帮助,请接受这个答案并点赞!!
void _filterSearch(String query) {
if (query.isNotEmpty) {
List<ApptUsersModel> dummyListData = [];
_dummySearchList.forEach((element) {
var fullName = (element.firstname!+element.lastname!).trim();
if (fullName.toLowerCase().contains(query.toLowerCase().replaceAll(' ', '').trim())) {
dummyListData.add(element);
}
});
Utility.log("Length of dummyListData is --> ${dummyListData.length}");
setState(() {
_searchResultList.clear();
_searchResultList.addAll(dummyListData);
Utility.log(
"Length of _searchResultList in if is --> ${_searchResultList.length}");
});
return;
}
}
英文:
You have not defined duplicateItems in your function or even global variable. You have to define it before using it. Weather duplicateItems is a String, int or some other type code doesn't know so we have to mention define it.In your case it is a list of String I guess as it is a search function so my answer is accordingly.
UPDATED Answer:- Here I have also made a change so that when there is space in the search query it will still give you a valid result and if it help please accept this answer and give an upvote !!
void _filterSearch(String query) {
if (query.isNotEmpty) {
List<ApptUsersModel> dummyListData = [];
_dummySearchList.forEach((element) {
var fullName = (element.firstname!+element.lastname!).trim();
if (fullName.toLowerCase().contains(query.toLowerCase().replaceAll(' ', '').trim())) {
dummyListData.add(element);
}
});
Utility.log("Length of dummyListData is --> ${dummyListData.length}");
setState(() {
_searchResultList.clear();
_searchResultList.addAll(dummyListData);
Utility.log(
"Length of _searchResultList in if is --> ${_searchResultList.length}");
});
return;
}
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论