首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误:无法使用静态访问访问实例成员“res”

错误:无法使用静态访问访问实例成员“res”
EN

Stack Overflow用户
提问于 2022-09-23 13:17:52
回答 2查看 554关注 0票数 0

我正在寻找一个元素。我使用的是AutoComplete小部件,用户可以在此输入并根据匹配的结果显示建议。我的数据来自邮政请求。早些时候,有一个Get请求,AutoComplete的建议对我有用,但现在它已经更改为Post请求。由于这个原因,现在我得到了这个错误Instance member 'res' can't be accessed using static access

这是我的search_model.dart

代码语言:javascript
运行
复制
    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;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-09-23 13:43:02

改变这个

代码语言:javascript
运行
复制
 return SearchSquad.res

代码语言:javascript
运行
复制
 SearchSquad? searchSquad;//instance for the class

 return searchSquad.res// change to this

我不知道你在哪里调用_getSearchSquad()函数,但你会明白

代码语言:javascript
运行
复制
 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
票数 1
EN

Stack Overflow用户

发布于 2022-09-23 13:22:50

在定义res static List<Re> res;之前添加一个静态关键字

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73828325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档