Home > front end >  Flutter error || Instance member 'res' can't be accessed using static access
Flutter error || Instance member 'res' can't be accessed using static access

Time:09-23

I am working on a searching for an element. I am using AutoComplete widget where users can type and based on matched results it will show suggestions. My data is coming from Post requests. Earlier there was a Get request and AutoComplete suggestion was working for me but now it has been changed to Post request. Due to this now I am getting this error Instance member 'res' can't be accessed using static access

This is my error

This is my 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;

CodePudding user response:

Add a static key word before defining res static List<Re> res;

CodePudding user response:

change this

 return SearchSquad.res

to

 SearchSquad? searchSquad;//instance for the class

 return searchSquad.res// change to this
  • Related