showRateUsDialog static method

Future<void> showRateUsDialog(
  1. MainJson mainJson
)

Implementation

static Future<void> showRateUsDialog(MainJson mainJson) async {
  final context = NavigationService.navigatorKey.currentContext;
  if (context == null) return;
  PackageInfo packageInfo = await PackageInfo.fromPlatform();
  if (Platform.isIOS) {
    showCupertinoDialog(
      context: context,
      barrierDismissible: true,
      builder: (context) => CupertinoAlertDialog(
        title: Text(packageInfo.appName),
        content: const Text(
          "If you like our app, would you mind taking a 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: context,
      barrierDismissible: true,
      builder: (context) {
        final isDark = Theme.of(context).brightness == Brightness.dark;
        final bgColor = isDark ? const Color(0xFF1E1E1E) : Colors.white;
        final titleColor = isDark ? Colors.white : Colors.black87;
        final contentColor = isDark ? Colors.white70 : Colors.black54;
        final secondaryColor = isDark ? Colors.grey[400]! : Colors.grey[700]!;
        return AlertDialog(
          backgroundColor: bgColor,
          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: TextStyle(fontWeight: FontWeight.bold, fontSize: 22, color: titleColor),
          ),
          content: Text(
            "If you like our app, would you mind taking a moment to rate us?",
            textAlign: TextAlign.center,
            style: TextStyle(color: contentColor, 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: secondaryColor,
                      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'] ?? '');
                    },
                  ),
                ),
              ],
            ),
          ],
        );
      },
    );
  }
}