我试图使用HTTP软件包将Flutter应用连接到MySQL。但是当我想要解码JSON时出现错误。但是,如果我打印不带List的JSON,则会出现问题。
import 'dart:convert';
import 'package:foodapps/src/models/food_model.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:http/http.dart' as http;
class FoodModel extends Model{
List<Food> _foods = [];
List<Food> get foods{
return List.from(_foods);
}
void addFood(Food food){
_foods.add(food);
}
void fetchFoods(){
http
.get("http://192.168.100.9/flutter_foodapps/api/foods/getfoods.php")
.then((http.Response response){
final List fetchedData = json.decode(response.body);
print(fetchedData);
});
}
}