CodePudding user response:
Whenever flutter is acting strange, I recommend running the following commands (close the debug session first):
Command 1
flutter clean
Command 2
flutter pub get
If it's still acting strange, it means that the problem is in the code.
Now, your code runs perfectly on my computer, so I'm not sure what the problem is. Although we can try another aproach with it:
Future<void> initAndSet() async {
var url = 'http://muhammeddevxd.pythonanywhere.com/api/ecommerce';
final response = await http.get(Uri.parse(url));
var extractedData =
List<Map<String, dynamic>>.from(jsonDecode(response.body));
extractedData.forEach((element) {
print(element);
});
}
!! Don't forget to import 'dart:convert' and 'package:http/http.dart' as http.