Тип данных во флаттере действительно меня беспокоит. Кажется, я не могу понять это. Может ли кто-нибудь помочь мне здесь? Я использую панель поиска Flappy для печати некоторых данных!
SearchBar<Dokan>(
onSearch: search,
onItemFound: (Dokan dokan, int index) {
return Container(....)
})
Это метод поиска, который получает List
Future<List<Dokan>> search(String search) async {
List<Dokan> dokans = await DokanApi.getAll('search', search);
setState(() {
this.isDescriptionPanelVisible = false;
this.searchBarHeight = dokans.length > 0
? 70.00 + double.parse((dokans.length * 80).toString())
: 120;
});
return dokans;
}
Это метод getAll, вызываемый выше
static Future<List<Dokan>> getAll([queryName, query]) async {
ApiResponse apiResponse =
await CallApi.get('dokans', queryName ?? null, query ?? null);
if (apiResponse.hasErrors()) return null;
return apiResponse.getData().map<Dokan>((dokanData) {
return Dokan.fromJson(dokanData);
}).toList();
}
Это Dokan из json метода.
static Dokan fromJson(dynamic json) {
return Dokan(
id: json['id'] ?? null,
owner: json['owner'] != null ? json['owner']['name'] : null,
location: json['location'] ?? null,
name: json['name'],
description: json['description'] ?? null,
lat: double.parse(json['lat']),
lng: double.parse(json['lng']),
averageRating: json['averageRating'] != null
? double.parse(json['averageRating'].toString())
: 0.0,
totalRating: json['totalRating'] ?? 0,
foodItems: json['food_items'] != null
? List<FoodItem>.from(json['food_items']
.map<FoodItem>((food) => FoodItem.fromJson(food))
.toList())
: null,
);
}
Я пропустил приведение типа здесь? Любая помощь будет оценена!