showSoftUpdateDialog static method

void showSoftUpdateDialog(
  1. BuildContext context,
  2. String url,
  3. String remoteVersion,
  4. VoidCallback onProceed,
)

Implementation

static void showSoftUpdateDialog(BuildContext context, String url, String remoteVersion, VoidCallback onProceed) {
  if (Platform.isIOS) {
    showCupertinoDialog(
      context: context,
      barrierDismissible: false,
      builder: (dialogContext) => CupertinoAlertDialog(
        title: const Text("New Version Available"),
        content: const Text(
          "A newer version of the app is available. Would you like to update now?",
        ),
        actions: <Widget>[
          CupertinoDialogAction(
            child: const Text("Update Later"),
            onPressed: () async {
              final prefs = await SharedPreferences.getInstance();
              prefs.setString('soft_update_last_shown_$remoteVersion', DateTime.now().toIso8601String());
              if (!dialogContext.mounted) return;
              Navigator.pop(dialogContext);
              onProceed();
            },
          ),
          CupertinoDialogAction(
            child: const Text("Update Now"),
            onPressed: () async {
              final prefs = await SharedPreferences.getInstance();
              prefs.setString('soft_update_last_shown_$remoteVersion', DateTime.now().toIso8601String());
              try { launchUrl(Uri.parse(url)); } catch (_) {}
              if (!dialogContext.mounted) return;
              Navigator.pop(dialogContext);
              onProceed();
            },
          ),
        ],
      ),
    );
  } else {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (dialogContext) {
        final isDark = Theme.of(dialogContext).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.system_update, size: 60, color: Colors.blueAccent),
          title: Text(
            "New Version Available",
            textAlign: TextAlign.center,
            style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22, color: titleColor),
          ),
          content: Text(
            "A newer version of the app is available. Would you like to update now?",
            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("LATER", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
                    onPressed: () async {
                      final prefs = await SharedPreferences.getInstance();
                      prefs.setString('soft_update_last_shown_$remoteVersion', DateTime.now().toIso8601String());
                      if (!dialogContext.mounted) return;
                      Navigator.pop(dialogContext);
                      onProceed();
                    },
                  ),
                ),
                const SizedBox(width: 10),
                Expanded(
                  child: ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Colors.blueAccent,
                      foregroundColor: Colors.white,
                      minimumSize: const Size(0, 50),
                      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
                    ),
                    child: const Text("UPDATE", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
                    onPressed: () async {
                      final prefs = await SharedPreferences.getInstance();
                      prefs.setString('soft_update_last_shown_$remoteVersion', DateTime.now().toIso8601String());
                      try { launchUrl(Uri.parse(url)); } catch (_) {}
                      if (!dialogContext.mounted) return;
                      Navigator.pop(dialogContext);
                      onProceed();
                    },
                  ),
                ),
              ],
            ),
          ],
        );
      },
    );
  }
}