I have a future that is used a few different times on some pages and I'm trying to include it instead and reference it when needed to cut down on the code overhead.
I've created a working future and wrapped it inside a class, the problem is that Flutter states that
"2 positional argument(s) expected, but 0 found."
I've tried String and Function type declarations for the client variable and I am including them, but I'm not sure what else I'm missing here?
FetchCats.getCats(client: http.Client(), filter: filter);
class FetchCats {
String client; <-- this shouldn't be string but I don't know what else to declare it as
int catType;
FetchCats({Key? key, required this.client, required this.catType});
Future<List<CatDetails>> getCats(http.Client client, int catType) async {
var ct = catType;
var catResults;
var response = await client.get(Uri.parse('/cats/breeds/$ct/'));
if (response.statusCode == 200) {
catResults = compute(convertCatDetails, response.body);
} else {
print("error");
}
return catResults;
}
}
List<CatDetails> convertCatDetails(String responseBody) {
final parsed = jsonDecode(responseBody).cast<Map<String, dynamic>>();
return parsed
.map<CatDetails>((json) => CatDetails.fromJson(json))
.toList();
}
>?'.
– VanCoon Jul 27 '22 at 20:45