OTA Update attempt

This commit is contained in:
2026-03-11 22:28:38 +08:00
parent f8c79acbbc
commit 0bd2a94ece
12 changed files with 687 additions and 3 deletions
+59
View File
@@ -0,0 +1,59 @@
/// Represents a row in the ``app_versions`` table on the server. The
/// `AppUpdateService` fetches the most recent entry and compares it against the
/// running application's build number.
class AppVersion {
/// Incrementing integer that matches the Android `versionCode`.
final int versionCode;
/// If the device is running a build number that is *strictly less* than this
/// value the update is considered "forced" and the user cannot continue
/// using the existing install.
final int minVersionRequired;
/// A publiclyaccessible URL pointing at an APK stored in Supabase Storage.
final String downloadUrl;
/// Markdown/plaintext release notes that will be shown in the dialog.
final String releaseNotes;
AppVersion({
required this.versionCode,
required this.minVersionRequired,
required this.downloadUrl,
required this.releaseNotes,
});
factory AppVersion.fromMap(Map<String, dynamic> map) {
return AppVersion(
versionCode: map['version_code'] as int,
minVersionRequired: map['min_version_required'] as int,
downloadUrl: map['download_url'] as String,
releaseNotes: map['release_notes'] as String? ?? '',
);
}
}
/// Helper type returned by ``AppUpdateService.checkForUpdate`` so callers can
/// decide how to present the UI.
class AppUpdateInfo {
/// The version that was returned from ``app_versions``. ``null`` when the
/// table was empty (should not happen in normal operation).
final AppVersion? latestVersion;
/// Current build number as reported by ``package_info_plus``.
final int currentBuildNumber;
/// ``true`` when ``currentBuildNumber < latestVersion.versionCode``.
final bool isUpdateAvailable;
/// ``true`` when ``currentBuildNumber < latestVersion.minVersionRequired``
/// (regardless of whether there is a newer release available).
final bool isForceUpdate;
AppUpdateInfo({
required this.currentBuildNumber,
required this.latestVersion,
required this.isUpdateAvailable,
required this.isForceUpdate,
});
}