checkAndPrompt static method
Main entry point for checking and prompting app updates.
Implementation
static Future<void> checkAndPrompt({
// Uri? apiEndpoint,
// required int totalMinutes,
String? notes,
int? repeat_totalminutes = 60,
bool forceUpdate = false,
}) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String updateLaterDateTime = "";
try {
updateLaterDateTime = prefs.getString("current_date")!;
} catch (_) {}
if (updateLaterDateTime.isNotEmpty) {
// print(Utility.isHoursPassed(updateLaterDateTime, repeat_totalminutes!));
if (!Utility.isHoursPassed(updateLaterDateTime)) {
return;
}
}
final info = await PackageInfo.fromPlatform();
CustomUpdateVersion? data;
try {
// If API endpoint provided, fetch from API
// Otherwise fetch from platform store
if (Platform.isAndroid) {
data = await _fetchFromPlayStore(info.packageName);
} else if (Platform.isIOS) {
data = await _fetchFromAppStore(info.packageName);
}
} catch (e) {
return;
}
// If no data or version found, stop
if (data == null || data.newVersion == null || data.newVersion!.isEmpty) {
return;
}
// Compare versions properly (semantic comparison)
final isUpdateAvailable =
_isNewVersionAvailable(info.version, data.newVersion!);
if (!isUpdateAvailable) {
return; // No update required
}
// Avoid showing multiple dialogs
if (UpdateBottomSheet.isUpdateDialogShowing.value) return;
// Show update dialog
await UpdateBottomSheet.showUpdateDialog(
// ignore: use_build_context_synchronously
info.version,
data,
forceUpdate,
notes: notes,
totalMinutes: repeat_totalminutes,
);
}