flutter_app_auto_update_checker 1.0.1
flutter_app_auto_update_checker: ^1.0.1 copied to clipboard
A lightweight, cross-platform Flutter package that automatically checks for app updates from Google Play Store and Apple App Store, compares versions, and shows customizable update dialogs.
π Flutter App Auto Update Checker #
A lightweight, cross-platform Flutter package that automatically checks for app updates from Google Play Store (Android) and Apple App Store (iOS), compares versions, and shows customizable update dialogs.
β¨ Features #
- β Cross-platform support - Works on both Android and iOS
- β Automatic version checking - Fetches latest version from app stores
- β Smart version comparison - Compares semantic versions accurately
- β Customizable dialog - Beautiful, customizable update dialog with release notes
- β Easy integration - Simple API with minimal code
- β Lightweight - No heavy dependencies
- β Production-ready - Built for real-world applications
π¦ Installation #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_app_auto_update_checker: ^1.0.0
Then run:
flutter pub get
π Quick Start #
1. Basic Usage #
import 'package:flutter_app_auto_update_checker/flutter_app_auto_update_checker.dart';
// Check for updates
final updateInfo = await UpdateCheckerService.checkForUpdate();
if (updateInfo.hasUpdate) {
// Show update dialog
UpdateDialog.show(context, updateInfo: updateInfo);
}
2. Complete Example #
import 'package:flutter/material.dart';
import 'package:flutter_app_auto_update_checker/flutter_app_auto_update_checker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
_checkForUpdate();
}
Future<void> _checkForUpdate() async {
// Check for updates
final updateInfo = await UpdateCheckerService.checkForUpdate();
if (updateInfo.hasUpdate && mounted) {
// Show update dialog
UpdateDialog.show(
context,
updateInfo: updateInfo,
title: 'Update Available!',
message: 'A new version of the app is available.',
updateButtonText: 'Update Now',
laterButtonText: 'Later',
isCritical: false, // Set to true for forced updates
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Auto Update Checker'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.check_circle_outline,
size: 64,
color: Colors.green,
),
const SizedBox(height: 16),
const Text(
'Update Check Complete',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
const Text('Your app is up to date!'),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: _checkForUpdate,
icon: const Icon(Icons.refresh),
label: const Text('Check Again'),
),
],
),
),
);
}
}
π API Reference #
UpdateCheckerService #
Main service class for checking app updates.
Methods
checkForUpdate({String? packageName})
Checks for app updates from the respective app store.
Parameters:
packageName(optional): The app's package name (Android) or bundle ID (iOS). If not provided, it will be fetched automatically.
Returns: Future<AppUpdateInfo>
Example:
final updateInfo = await UpdateCheckerService.checkForUpdate();
AppUpdateInfo #
Model class containing app update information.
Properties:
currentVersion(String): The current version of the installed applatestVersion(String): The latest version available on the storehasUpdate(bool): Whether an update is availablepackageName(String): The app's package name (Android) or bundle ID (iOS)storeUrl(String): The URL to the app store listingreleaseNotes(String?): Release notes or changelog for the updateisCritical(bool): Whether this is a critical/forced update
Example:
if (updateInfo.hasUpdate) {
print('Update available: ${updateInfo.currentVersion} -> ${updateInfo.latestVersion}');
}
UpdateDialog #
A customizable dialog widget for displaying app update information.
Constructor
UpdateDialog({
required AppUpdateInfo updateInfo,
String title = 'Update Available',
String? message,
String updateButtonText = 'Update Now',
String laterButtonText = 'Later',
bool showLaterButton = true,
VoidCallback? onUpdatePressed,
VoidCallback? onLaterPressed,
bool isCritical = false,
})
Static Method: show()
Shows the update dialog.
Parameters:
context(BuildContext): The build contextupdateInfo(AppUpdateInfo): The app update information to displaytitle(String): Title of the dialog (default: 'Update Available')message(String?): Message to display in the dialogupdateButtonText(String): Text for the update button (default: 'Update Now')laterButtonText(String): Text for the later button (default: 'Later')showLaterButton(bool): Whether to show the later button (default: true)onUpdatePressed(VoidCallback?): Callback when update button is pressedonLaterPressed(VoidCallback?): Callback when later button is pressedisCritical(bool): Whether this is a critical update (forces update) (default: false)
Example:
UpdateDialog.show(
context,
updateInfo: updateInfo,
title: 'New Version Available!',
message: 'Please update to the latest version.',
updateButtonText: 'Update Now',
laterButtonText: 'Maybe Later',
isCritical: false,
);
π¨ Customization #
Custom Update Dialog #
You can customize the update dialog by providing your own callbacks:
UpdateDialog.show(
context,
updateInfo: updateInfo,
title: 'Update Required',
message: 'This update includes important security fixes.',
updateButtonText: 'Update Now',
laterButtonText: 'Remind Me Later',
showLaterButton: false, // Hide later button for critical updates
isCritical: true, // Force update (prevents dismissing dialog)
onUpdatePressed: () {
// Custom action when update is pressed
print('Update pressed!');
},
onLaterPressed: () {
// Custom action when later is pressed
print('Later pressed!');
},
);
Forced Updates #
To force users to update (prevent dismissing the dialog):
UpdateDialog.show(
context,
updateInfo: updateInfo,
isCritical: true, // This prevents dismissing the dialog
);
π§ Advanced Usage #
Check Updates on App Launch #
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
home: const HomePage(),
builder: (context, child) {
// Check for updates when app starts
WidgetsBinding.instance.addPostFrameCallback((_) {
_checkForUpdate(context);
});
return child!;
},
);
}
Future<void> _checkForUpdate(BuildContext context) async {
final updateInfo = await UpdateCheckerService.checkForUpdate();
if (updateInfo.hasUpdate && context.mounted) {
UpdateDialog.show(context, updateInfo: updateInfo);
}
}
}
Check Updates Periodically #
class UpdateChecker {
static Timer? _timer;
static void startPeriodicCheck(BuildContext context) {
_timer = Timer.periodic(const Duration(hours: 24), (timer) async {
final updateInfo = await UpdateCheckerService.checkForUpdate();
if (updateInfo.hasUpdate && context.mounted) {
UpdateDialog.show(context, updateInfo: updateInfo);
}
});
}
static void stopPeriodicCheck() {
_timer?.cancel();
_timer = null;
}
}
π Troubleshooting #
Issue: Update not detected #
Solution: Make sure your app is published on the app store. The package fetches version information from the official app store pages.
Issue: iOS version not detected #
Solution: The iTunes Search API might take some time to index your app after publishing. Wait a few hours and try again.
Issue: Android version not detected #
Solution: Ensure your app is published on Google Play Store and the package name matches exactly.
π License #
This project is licensed under the MIT License - see the LICENSE file for details.
π¨βπ» Author #
Raza Khan
- GitHub: @m-raza-dreamy
- GitHub: @thisiskhan
π€ Contributing #
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
β Support #
If you like this package, please consider giving it a β on pub.flutter-io.cn!
π Changelog #
See CHANGELOG.md for a list of changes.
π Links #
Made with β€οΈ by Raza Khan