fetchPopupData method

Future<void> fetchPopupData(
  1. BuildContext context
)

Implementation

Future<void> fetchPopupData(BuildContext context) async {

  String packageName = (await PackageInfo.fromPlatform()).packageName;

  try {
    final response = await http.post(
      Uri.parse('https://flutter.oneconnect.top/view/front/controller.php'),
      body: {
        'action': 'popUpSettings',
        'package_name': packageName,
        'api_key': apiKey
      },
    );

    if (response.statusCode == 200) {
      final Map<String, dynamic> data = json.decode(response.body);

      message = data['message'];
      title = data['title'];
      link = data['link'];
      image = data['image'];
      logo = data['logo'];
      ctaText = data['cta_text'];
      final int active = int.parse(data['active']);
      final int frequency = int.parse(data['frequency']);
      final int noPopup = int.parse(data['popup']);
      showStar = int.parse(data['show_star']);

      bool popupStatus = await showPopup(frequency);

      //print("CHECKACTIVE $noPopup");

      if (active == 1 && popupStatus && noPopup == 0) {
        _showCustomPopup(context);
      }
    } else {
      print('Error fetching popup data: ${response.statusCode}');
    }
  } catch (e) {
    print('Error: $e');
  }
}