I'm trying to write json data from a third-party site on a flater, but I've already tried different options. I get the same problem on the last step. Please help me very much.
i have this model
class SkinModel {
String src;
String name;
double minprice;
int count;
double avgprice;
double medianprice;
int popularity;
SkinModel(
{required this.src,
required this.name,
required this.minprice,
required this.count,
required this.avgprice,
required this.medianprice,
required this.popularity});
factory SkinModel.fromJson(Map<String, dynamic> json) {
return SkinModel(
src: json['src'],
name: json['name'],
minprice: json['minprice'],
count: json['count'],
avgprice: json['avgprice'],
medianprice: json['medianprice'],
popularity: json['popularity'],
);
}
}
and such a class for receiving and processing data
import 'dart:convert';
import 'package:flutter_application_1/data_skins.dart';
import 'package:flutter_application_1/model/model_skin.dart';
import 'package:http/http.dart' as http;
class Skins {
Future<dynamic>? getSkinsPopular(String game, String? method) async {
late List<SkinModel> skinListModel = [];
if (method == null) {
skinListModel = skinssamplelist;
}
String url = 'https://market.dota2.net/api/v2/prices/USD.json';
print('Step 1 ' + url);
http.Response response = await http.get(
Uri.parse(url),
);
print('Step 2 ' + response.reasonPhrase!);
if (response.statusCode == 200) {
var decodeData = json.decode(response.body);
var rest = decodeData['items'] as List;
print('Step 3');
print(rest);
skinListModel =
rest.map<SkinModel>((json) => SkinModel.fromJson(json)).toList();
print('Step 4');
print(skinListModel);
} else {
throw 'Problem with get request';
}
return skinListModel;
}
}
}
But the last successful step 3 and after the debugger writes flutter: Sorry try again I absolutely do not understand what the error is and what I did wrong