我的乌特产阶级采用的方法如下: 一个用于检查网络连接和显示进展方言。
static Future<bool> isInternet() async
{
bool result = await InternetConnectionChecker().hasConnection;
return result;
}
static ShowProgress(BuildContext context) {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Center(
child: SpinKitRotatingCircle(color: const Color(0xff2799fa), size: 60.0, ),
);
});
}
我需要将其应用到下文的APIC电话部分:
class _UserDetailsState extends State<UserDetails> {
ProfileResponse? profileResponse;
Future<void> fetchData() async {
try {
//Utility.ShowProgress(context);
final response = await getProfileDetails();
if (response.statusCode == 200) {
Map<String, dynamic> parsedData = jsonDecode(response.body);
setState(() {
profileResponse = ProfileResponse.fromJson(parsedData);
});
} else {
// setState(() {
// _data = Error: ${response.statusCode} ;
// });
}
} catch (error) {
// setState(() {
// _data = Error: $error ;
// });
}
//Navigator.of(context).pop();
}
@override
void initState() {
fetchData();
}
@override
Widget build(BuildContext context) {
return Container(
)
}
Future<http.Response> getProfileDetails() async{
if(await Utility.isInternet()){
final SharedPreferences prefs = await SharedPreferences.getInstance();
//reading values from SharedPreferences and calling the API
final String url = My API Path;
final response = await http.get(Uri.parse(url));
return response;
}
else{
//show no network alert
}
}
我在<代码>fetchData()中添加了“ProgressDialog,如该守则中评论的代码,但该编码在《国际投资指南》中并未显示使用该软件。
此外,我还增加了关于<代码>植被详细数据(代码>)的网络核对,但显示的是以下错误。
The body might complete normally, causing null to be returned, but the return type, FutureOr , is a potentially non-nullable type. Try adding either a return or a throw statement at the end.
我如何解决这两个问题?