app_update_helper 1.0.0
app_update_helper: ^1.0.0 copied to clipboard
Simply check for updates, then based on the version (major, minor, patch) decide to update or not.
example/lib/main.dart
import 'package:app_update_helper/app_update_helper.dart';
import 'package:flutter/material.dart';
void checkForUpdates() async {
final info = await AppUpdateHelper.checkForUpdates();
if (info == null) return; // No update available
// let's say you want to update only if major/minor
switch (info.updateType) {
case UpdateType.major:
case UpdateType.minor:
AppUpdateHelper.update();
break;
case UpdateType.patch:
debugPrint("Patch Update Available: ${info.newVersion}");
}
// or if you only care about major updates
if (info.isMajorUpdate) AppUpdateHelper.update();
// or maybe if patch and multiple of 3 (who am I to judge?)
if (info.isPatchUpdate && info.newVersion.patch % 3 == 0) {
AppUpdateHelper.update();
}
}
void main() {
checkForUpdates();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(home: Placeholder());
}
}