showRateUsDialog static method

Future<void> showRateUsDialog(
  1. MainJson mainJson
)

Implementation

static Future<void> showRateUsDialog(MainJson mainJson) async {
  PackageInfo packageInfo = await PackageInfo.fromPlatform();
  if (Platform.isIOS) {
    showCupertinoDialog(
      context: NavigationService.navigatorKey.currentContext!,
      barrierDismissible: true,
      builder: (context) => CupertinoAlertDialog(
        title: Text(packageInfo.appName),
        content: const Text(
          "If you like our app. Would you mind to take moment to Rate Us.",
        ),
        actions: <Widget>[
          CupertinoDialogAction(
            child: const Text("Not now"),
            onPressed: () async {
              final prefs = await SharedPreferences.getInstance();
              await prefs.setString('rate_us_not_now_timestamp', DateTime.now().toIso8601String());
              mainJson.isReviewDialogOpen = false;
              if (!context.mounted) return;
              Navigator.pop(context);
            },
          ),
          CupertinoDialogAction(
            child: const Text("Rate"),
            onPressed: () async {
              final prefs = await SharedPreferences.getInstance();
              await prefs.setBool('rate_us_completed', true);
              mainJson.isReviewDialogOpen = false;
              if (!context.mounted) return;
              Navigator.pop(context);
              RateUs().showRateUsDialog(
                fallbackUrl: mainJson.data?['app']?['app_store_url'] ?? '',
              );
            },
          ),
        ],
      ),
    );
  } else {
    showDialog(
      context: NavigationService.navigatorKey.currentContext!,
      barrierDismissible: true,
      builder: (context) => AlertDialog(
        backgroundColor: Colors.white,
        surfaceTintColor: Colors.transparent,
        elevation: 10,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20),
        ),
        icon: const Icon(Icons.star_rounded, size: 60, color: Colors.amber),
        title: Text(
          "Enjoying ${packageInfo.appName}?",
          textAlign: TextAlign.center,
          style: const TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 22,
            color: Colors.black87,
          ),
        ),
        content: const Text(
          "If you like our app, would you mind taking a moment to rate us?",
          textAlign: TextAlign.center,
          style: TextStyle(color: Colors.black54, fontSize: 16),
        ),
        actionsAlignment: MainAxisAlignment.center,
        actionsPadding: const EdgeInsets.only(bottom: 20, left: 20, right: 20),
        actions: <Widget>[
          Row(
            children: [
              Expanded(
                child: TextButton(
                  style: TextButton.styleFrom(
                    foregroundColor: Colors.grey[700],
                    minimumSize: const Size(0, 50),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(15),
                    ),
                  ),
                  child: const Text("NOT NOW", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
                  onPressed: () async {
                    final prefs = await SharedPreferences.getInstance();
                    await prefs.setString('rate_us_not_now_timestamp', DateTime.now().toIso8601String());
                    mainJson.isReviewDialogOpen = false;
                    if (!context.mounted) return;
                    Navigator.pop(context);
                  },
                ),
              ),
              const SizedBox(width: 10),
              Expanded(
                child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    backgroundColor: Colors.amber,
                    foregroundColor: Colors.white,
                    minimumSize: const Size(0, 50),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(15),
                    ),
                  ),
                  child: const Text("RATE", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
                  onPressed: () async {
                    final prefs = await SharedPreferences.getInstance();
                    await prefs.setBool('rate_us_completed', true);
                    mainJson.isReviewDialogOpen = false;
                    if (!context.mounted) return;
                    Navigator.pop(context);
                    RateUs().showRateUsDialog(
                      fallbackUrl: mainJson.data?['app']?['app_store_url'] ?? '',
                    );
                  },
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}