Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dart Instance of the class name

i have "data" from from api but i keep geting instance of the class name, which i did not know where the error is coming from..

here is the code

getalRegion() async {
    final pref = await SharedPreferences.getInstance();
    final autorization = pref.getString("jwt") ?? "";
    try {
      var url = Uri.parse("https://sss.com/api/Region/Regions");
      Response response = await http.get(url, headers: {
        "Authorization": "Bearer $autorization",
      });
      if (response.statusCode == 200) {
        final List<Map<String, dynamic>> result =
            List<Map<String, dynamic>>.from(
                jsonDecode(utf8.decode(response.bodyBytes)));
        final getResult = result.map((e) => RegoinDetails.fromJson(e)).toList();
        freshRegion = getResult;
        print(freshRegion);
      }
    } catch (e) {
      log("$e");
    }
  }



[Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails', Instance of 'RegoinDetails']

here is the class

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import 'dart:convert';

List<RegoinDetails> regoinDetailsFromJson(String str) =>
    List<RegoinDetails>.from(
        json.decode(str).map((x) => RegoinDetails.fromJson(x)));

String regoinDetailsToJson(List<RegoinDetails> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class RegoinDetails {
  RegoinDetails({
    required this.regionCode,
    required this.regionName,
  });

  String regionCode;
  String regionName;

  factory RegoinDetails.fromJson(Map<String, dynamic> json) => RegoinDetails(
        regionCode: json["regionCode"],
        regionName: json["regionName"],
      );

  Map<String, dynamic> toJson() => {
        "regionCode": regionCode,
        "regionName": regionName,
      };
}

>Solution :

u will have to override toString in the RegoinDetails model with the properties that u need to see on the output

class RegoinDetails {
  RegoinDetails({
    required this.regionCode,
    required this.regionName,
  });

  String regionCode;
  String regionName;

  factory RegoinDetails.fromJson(Map<String, dynamic> json) => RegoinDetails(
        regionCode: json["regionCode"],
        regionName: json["regionName"],
      );

  Map<String, dynamic> toJson() => {
        "regionCode": regionCode,
        "regionName": regionName,
      };
  @override
  String toString() {
    return 'RegoinDetails(regionCode: $regionCode, regionName: $regionName )';
  }
}


Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading