【问题标题】:Flutter error || Instance member 'res' can't be accessed using static access颤振错误 ||无法使用静态访问访问实例成员 \'res\'
【发布时间】:2022-09-23 21:22:50
【问题描述】:

我正在寻找一个元素。我正在使用自动完成小部件,用户可以在其中键入并根据匹配的结果显示建议。我的数据来自 Post 请求。早些时候有一个 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;

    标签: flutter flutter-layout flutter-web


    【解决方案1】:

    在定义res之前添加静态关键字static List&lt;Re&gt; res;

    【讨论】:

      猜你喜欢
      • 2020-11-29
      • 2021-08-19
      • 2021-11-26
      • 1970-01-01
      • 2023-04-10
      • 2020-09-19
      • 2021-03-22
      • 2021-10-31
      • 2020-01-03
      相关资源
      最近更新 更多