我正在寻找一个元素。我使用的是AutoComplete小部件,用户可以在此输入并根据匹配的结果显示建议。我的数据来自邮政请求。早些时候,有一个Get请求,AutoComplete的建议对我有用,但现在它已经更改为Post请求。由于这个原因,现在我得到了这个错误Instance member 'res' can't be accessed using static access
这是我的search_model.dart
SearchSquad searchSquadFromJson(String str) =>
SearchSquad.fromJson(json.decode(str));
String searchSquadToJson(SearchSquad data) => json.encode(data.toJson());
class SearchSquad {
SearchSquad({
required this.count,
required this.res,
});
int count;
List<Re> res;
factory SearchSquad.fromJson(Map<String, dynamic> json) => SearchSquad(
count: json["count"],
res: List<Re>.from(json["res"].map((x) => Re.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"count": count,
"res": List<dynamic>.from(res.map((x) => x.toJson())),
};
}
class Re {
Re({
required this.squadId,
required this.squadName,
required this.defaultProfileImageId,
required this.profimgid,
required this.profimgname,
required this.profimgurl,
required this.profimgrotation,
this.profimgposition1,
this.profimgposition2,
required this.profimgscale,
this.profimgrotationfocuspoint1,
this.profimgrotationfocuspoint2,
});
String squadId;
String squadName;
String defaultProfileImageId;
String profimgid;
String profimgname;
String profimgurl;
int profimgrotation;
dynamic profimgposition1;
dynamic profimgposition2;
double profimgscale;
dynamic profimgrotationfocuspoint1;
dynamic profimgrotationfocuspoint2;
发布于 2022-09-23 13:43:02
改变这个
return SearchSquad.res
至
SearchSquad? searchSquad;//instance for the class
return searchSquad.res// change to this
我不知道你在哪里调用_getSearchSquad()
函数,但你会明白
SearchSquad? searchSquad; //instance for the class
void getSearch() async{
searchSquad = await _getSearchSquad(); //await it since its Future and put it in async function
}
return searchSquad.res// then use it in the return of AuthoComplete
发布于 2022-09-23 13:22:50
在定义res static List<Re> res;
之前添加一个静态关键字
https://stackoverflow.com/questions/73828325
复制相似问题