app_upgrader 0.0.4 app_upgrader: ^0.0.4 copied to clipboard
a Flutter package designed to handle application upgrades seamlessly.
App Upgrader #
Introduction #
App Upgrader is a Flutter package designed to handle application upgrades seamlessly. It addresses common challenges faced by developers when managing app updates, particularly in scenarios involving phased rollouts in app stores. The package is built upon the foundations laid by new_version
and in_app_update
packages, and we extend our gratitude to their contributors for their groundwork.
Key Features #
- Versatile Version Management: Fetch version information from your own services or remote configurations like Firebase, allowing for flexible update scenarios.
- Phased Rollout Compatibility: Tackle the issue of phased rollouts in app stores where not all users see the same version, preventing endless update loops.
- Local Testing Support: Unlike other packages, App Upgrader allows for local testing of update scenarios, making development and debugging simpler.
- Complex Update Scenarios: Handles intricate update sequences, like when the latest version requires a force update but intermediate versions require flexible updates.
- Special Thanks: Our solution for complex update scenarios was inspired by bugragny. Thank you for your contributions!
App Upgrader is your go-to solution for a hassle-free app update experience.
Getting Started #
To use App Upgrader, simply add it to your pubspec.yaml
file:
dependencies:
app_upgrader: ^latest_version
Then, import it in your Flutter app:
import 'package:app_upgrader/app_upgrader.dart';
Basic Usage #
Here's a quick example to get you started with App Upgrader:
AppUpgrader(
versionInfoFetcher: MyVersionInfoFetcher(),
bundleId: 'com.example.app',
child: MyApp(),
)
Advanced Usage with go_router #
Integrating with navigation frameworks like go_router is straightforward:
GlobalKey<NavigatorState> navigatorKey = GlobalKey();
AppUpgrader(
navigatorKey: navigatorKey,
versionInfoFetcher: MyVersionInfoFetcher(),
bundleId: 'com.example.app',
child: MaterialApp.router(
routerDelegate: _router.delegate(navigatorKey: navigatorKey),
routeInformationParser: _router.defaultRouteParser(),
// other MaterialApp.router parameters...
),
)
Documentation #
- child: child is the widget located directly below AppUpgrader in the widget hierarchy. It's typically the root widget of your application, like MaterialApp or CupertinoApp.
AppUpgrader(
child: MyApp(),
// ...
)
- navigatorKey: Used to integrate with MaterialApp.router for advanced navigation management.
GlobalKey<NavigatorState> navigatorKey = GlobalKey();
- versionInfoFetcher: Defines an interface for fetching version information. Implement this class to customize how version information is fetched, for instance, from Firebase Remote Config or a custom backend.
class MyVersionInfoFetcher implements VersionInfoFetcher {
late final FirebaseRemoteConfig firebaseRemoteConfig;
@override
Future<Map<String, dynamic>> fetchVersionInfo() {
// Implement fetching logic here.
// you can use your own service or firebase.
// for example we use firebase remote config
await firebaseRemoteConfig.fetchAndActivate();
return jsonDecode(firebaseRemoteConfig.getString(
Platform.isAndroid ? 'android_version_info' : 'ios_version_info'));
}
}
- bundleId: The unique identifier for your app, essential for fetching version information from app stores.
bundleId: 'com.example.myapp',
- langCode: An optional parameter for specifying the language code when fetching app version information from the iOS App Store.
langCode: 'en', // English language
- logger: An abstract class for logging purposes throughout the AppUpgrade process. Useful for debugging and testing, especially in local environments.
class MyAppUpgradeLogger implements AppUpgradeLogger {
@override
void log(String message) {
// Logging logic here...
}
}
- showCustomUpdateDialog: A callback function that allows you to display a custom dialog for app updates. It is triggered when an update is detected, and you can tailor the dialog based on the type of update.
showCustomUpdateDialog: (updateType, currentVersion, storeVersion) {
// Different behavior based on update type
switch (updateType) {
case UpdateType.forceUpdate:
// Force update: user must update the app
showDialog(
context: context,
barrierDismissible: false, // User must take action
builder: (BuildContext context) {
return AlertDialog(
title: Text('Mandatory Update'),
content: Text(
'Version $storeVersion is available and is a mandatory update.'
),
actions: <Widget>[
TextButton(
child: Text('Update Now'),
onPressed: () {
// Add your update action here
},
),
],
);
},
);
break;
case UpdateType.flexible:
// Flexible update: user can choose to update now or later
showDialog(
context: context,
barrierDismissible: true, // User can dismiss the dialog
builder: (BuildContext context) {
return AlertDialog(
title: Text('New Update Available'),
content: Text(
'Version $storeVersion is available. Would you like to update?'
),
actions: <Widget>[
TextButton(
child: Text('Later'),
onPressed: () => Navigator.of(context).pop(),
),
TextButton(
child: Text('Update Now'),
onPressed: () {
// Add your update action here
},
),
],
);
},
);
break;
default:
// No update or another update type
break;
}
}
- isLocalTest: A flag to enable testing behaviors in local development. Set it to true for testing update processes without the need for publishing a new version.
isLocalTest: true,
Contributing #
Contributions to App Upgrader are welcome! Whether it's submitting bug reports, feature requests, or contributing to the code, we appreciate your effort to make App Upgrader better.
License #
App Upgrader is released under the BSD 3-Clause.
Happy Coding!