【发布时间】:2021-04-02 04:13:49
【问题描述】:
我收到此错误:A value of type 'Future<Response>' can't be assigned to a variable of type 'Response'. Try changing the type of the variable, or casting the right-hand type to 'Response'.
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class loadding extends StatefulWidget {
@override
_loaddingState createState() => _loaddingState();
}
class _loaddingState extends State<loadding> {
void gateData() async {
var url =
Uri.parse('http://worldtimeapi.org/api/timezone/Africa/Addis_Ababa');
//here is The Error occur at http.get(url),
http.Response response = http.get(url);
}
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
【问题讨论】:
-
你需要把
await放在http.get之前