fetchData method

Future fetchData()

Implementation

Future fetchData() async {
  try {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    String packageName = packageInfo.packageName;
    String url =
        'https://products-69a92.web.app/${packageName.replaceAll('.', '_')}.json';

    final response = await http.get(Uri.parse(url));

    if (response.statusCode == 200) {
      admodel = AdModel.fromJson(jsonDecode(response.body));
      await NativeBridge.sendAdmobKey(admodel?.getAdmobKey ?? '');
    } else {
      if (kDebugMode) {
        print('Failed to load ad configuration: ${response.statusCode}');
      }
    }
  } catch (e) {
    if (kDebugMode) {
      print('Error fetching ad configuration: $e');
    }
  }
}