I'm building an app using Flutter which shows world time. I'm using the worldtimeapi for that but I'm running into this same error. I'm getting the output but the runtime error isn't going. How do I fix this error?
Here's the dart file loading.dart where the API is being used
import 'package:flutter/material.dart';
// Importing http package with alias http
import 'dart:convert';
import 'package:http/http.dart';
class Loading extends StatefulWidget {
const Loading({Key? key}) : super(key: key); // Fixed typo in super constructor
@override
State<Loading> createState() => _LoadingState();
}
class _LoadingState extends State<Loading> {
void getTime() async{
// Make the request using http.get
Response response = await get(Uri.http('worldtimeapi.org', '/api/timezone/Asia/Karachi'));
Map<String, dynamic> data = jsonDecode(response.body);
print(data);
// Get properties from data
String datetime = data['datetime'];
String offset = data['utc_offset'];
print(datetime);
print(offset);
// Create DateTime object
DateTime now = DateTime.parse(datetime);
print(now);
}
@override
void initState() {
super.initState();
getTime(); // Async func
print('hey there!');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Text('loading screen'),
);
}
}
and this is a snippet of the error message
E/AndroidRuntime(22278):
E/AndroidRuntime(22457): at android.app.ActivityThread.installProvider(ActivityThread.java:7754)
E/AndroidRuntime(22457): at android.app.ActivityThread.acquireProvider(ActivityThread.java:7352)
E/AndroidRuntime(22457): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:3668)
E/AndroidRuntime(22457): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2542)
E/AndroidRuntime(22457): at android.content.ContentResolver.query(ContentResolver.java:1213)
E/AndroidRuntime(22457): at android.content.ContentResolver.query(ContentResolver.java:1161)
E/AndroidRuntime(22457): at android.content.ContentResolver.query(ContentResolver.java:1117)
E/AndroidRuntime(22457): at cmkx.k(:com.google.android.gms@[email protected] (190400-535401451):2)
E/AndroidRuntime(22457): at cmkx.l(:com.google.android.gms@[email protected] (190400-535401451):1)
E/AndroidRuntime(22457): at cmkx.e(:com.google.android.gms@[email protected] (190400-535401451):4)
E/AndroidRuntime(22457): at cvdn.a(:com.google.android.gms@[email protected] (190400-535401451):0)
E/AndroidRuntime(22457): at cvdk.a(:com.google.android.gms@[email protected] (190400-535401451):1)
E/AndroidRuntime(22457): at cvdp.a(:com.google.android.gms@[email protected] (190400-535401451):2)
E/AndroidRuntime(22457): at cvep.m(:com.google.android.gms@[email protected] (190400-535401451):6)
E/AndroidRuntime(22457): at cvep.g(:com.google.android.gms@[email protected] (190400-535401451):11)
E/AndroidRuntime(22457): at egur.B(:com.google.android.gms@[email protected] (190400-535401451):0)
E/AndroidRuntime(22457): at com.google.android.gms.chimera.GmsAppComponentFactory.instantiateProvider(:com.google.android.gms@[email protected] (190400-535401451):9)
E/AndroidRuntime(22457): at android.app.ActivityThread.installProvider(ActivityThread.java:7754)
E/AndroidRuntime(22457): at android.app.ActivityThread.acquireProvider(ActivityThread.java:7352)
E/AndroidRuntime(22457): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:3668)
E/AndroidRuntime(22457): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2542)
E/AndroidRuntime(22457): at android.content.ContentResolver.query(ContentResolver.java:1213)
E/AndroidRuntime(22457): at android.content.ContentResolver.query(ContentResolver.java:1161)
E/AndroidRuntime(22457): at android.content.ContentResolver.query(ContentResolver.java:1117)
E/AndroidRuntime(22457): at cmkx.k(:com.google.android.gms@[email protected] (190400-535401451):2)
E/AndroidRuntime(22457): at cmkx.l(:com.google.android.gms@[email protected] (190400-535401451):1)
E/AndroidRuntime(22457): at cmkx.e(:com.google.android.gms@[email protected] (190400-535401451):4)
E/AndroidRuntime(22457): at cvdn.a(:com.google.android.gms@[email protected] (190400-5354
I tried adding a dependency in build.gradle, I've also checked the API and the http protocol and they seem to be working fine. I reckon the problem is not with the code but with the configurations of the system. Please help!
i too have this error. i tested again by creating a whole new default flutter project on VSC but still encounter this same error. running flutter doctor does not prompt any errors and i have also downloaded all the necessary SDK except for Visual Studio tool kit for mobile development