【发布时间】:2019-11-22 17:48:01
【问题描述】:
我正在尝试使用静态数据的示例项目,并通过对 Flutter 端点的 http 调用使其动态化。
编辑 --- JSON 代码
Future<User> getUsers(String groupID ) async {
final response =
await http.post('http://url/api/GetUsers',
headers: {"Content-Type": "application/json",
'Accept': 'application/json',},
body: json.encode({'groupID' : groupID}));
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
User _users;
_users = User.fromJson(json.decode(response.body));
return _users;
数据的格式是这样的:
List<Pokemon> _pokemonList = [
Pokemon(id: 1, name: 'Bill Smith',type: 'Caregiver', image: 'assets/images/KC_logo.png'),
Pokemon(id: 2, name: 'Joy Smith',type: 'Caregiver', image: 'assets/images/pokimon_2.png'),
Pokemon(id: 3, name: 'Joe Smith',type: 'Member', image: 'assets/images/pokimon_3.png'),
Pokemon(id: 4, name: 'Pete Smith',type: 'Member', image: 'assets/images/pokimon_4.png'),
Pokemon(id: 5, name: 'Steve Smith',type: 'Caregiver', image: 'assets/images/pokimon_5.png'),
Pokemon(id: 6, name: 'Paul Smith',type: 'Member', image: 'assets/images/pokimon_6.png'),
Pokemon(id: 7, name: 'Balbasaur',type: 'Grass', image: 'assets/images/pokimon_7.png'),
Pokemon(id: 8, name: 'Balbasaur',type: 'Water', image: 'assets/images/pokimon_8.png'),
Pokemon(id: 9, name: 'Balbasaur',type: 'Rock', image: 'assets/images/pokimon_9.png'),
Pokemon(id: 11, name: 'Charlizard',type: 'Fire', image: 'assets/images/pokimon_11.png'),
Pokemon(id: 12, name: 'Charlizard',type: 'Rock', image: 'assets/images/pokimon_12.png'),
Pokemon(id: 13, name: 'Charlizard',type: 'Grass', image: 'assets/images/pokimon_13.png'),
Pokemon(id: 14, name: 'Charlizard',type: 'Water', image: 'assets/images/pokimon_14.png'),
Pokemon(id: 15, name: 'Charlizard',type: 'Fire', image: 'assets/images/pokimon_15.png'),
Pokemon(id: 16, name: 'Charlizard',type: 'Grass', image: 'assets/images/pokimon_16.png'),
Pokemon(id: 17, name: 'Charlizard',type: 'Fire', image: 'assets/images/pokimon_17.png'),
Pokemon(id: 18, name: 'Charlizard',type: 'Water', image: 'assets/images/pokimon_18.png'),
Pokemon(id: 19, name: 'Charlizard',type: 'Rock', image: 'assets/images/pokimon_19.png'),
Pokemon(id: 20, name: 'Charlizard',type: 'Fire', image: 'assets/images/pokimon_20.png'),
Pokemon(id: 21, name: 'Charlizard',type: 'FiWaterre', image: 'assets/images/pokimon_21.png'),
Pokemon(id: 22, name: 'Charlizard',type: 'Grass', image: 'assets/images/pokimon_22.png'),
Pokemon(id: 23, name: 'Charlizard',type: 'Rock', image: 'assets/images/pokimon_23.png'),
Pokemon(id: 24, name: 'Charlizard',type: 'Grass', image: 'assets/images/pokimon_24.png'),
Pokemon(id: 25, name: 'Pichu',type: 'Water', image: 'assets/images/pokimon_25.png'),
Pokemon(id: 26, name: 'Charmender',type: 'Fire', image: 'assets/images/pokimon_26.png'),
Pokemon(id: 27, name: 'Charlizard',type: 'Rock', image: 'assets/images/pokimon_27.png'),
];
}
如何在 Dart 中实现这一点?
【问题讨论】:
-
请详细说明您真正想要做什么?你要调用api吗?
-
是的,我将调用 asp.net 中内置的 webAPI