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(),
              );
              launchUrl(Uri.parse(url));
              if (!dialogContext.mounted) return;
              Navigator.pop(dialogContext);
              onProceed();
            },
          ),
        ],
      ),
    );
  } else {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (dialogContext) => AlertDialog(
        backgroundColor: Colors.white,
        surfaceTintColor: Colors.transparent,
        elevation: 10,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20),
        ),
        icon: const Icon(Icons.system_update, size: 60, color: Colors.blueAccent),
        title: const Text(
          "New Version Available",
          textAlign: TextAlign.center,
          style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 22,
            color: Colors.black87,
          ),
        ),
        content: const Text(
          "A newer version of the app is available. Would you like to update now?",
          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("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(),
                    );
                    launchUrl(Uri.parse(url));
                    if (!dialogContext.mounted) return;
                    Navigator.pop(dialogContext);
                    onProceed();
                  },
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}