app_upgrader 0.1.0 app_upgrader: ^0.1.0 copied to clipboard
a Flutter package designed to handle application upgrades seamlessly.
App Upgrader #
Introduction #
App Upgrader is a Flutter package expertly crafted to manage application upgrades. It effortlessly addresses the challenges developers face while handling app updates. Our package is especially adept in scenarios involving phased rollouts in app stores. We proudly build upon the strong foundations laid by the new_version and in_app_update packages, and we extend our heartfelt gratitude to their contributors for their pioneering work.
🚀 Key Highlight: Smart Update Types #
- Force Update: When critical updates are necessary, App Upgrader ensures that users must update the app to continue its use. It's crucial for fixing security vulnerabilities or major bugs.
- Flexible Update:: For less critical updates, App Upgrader allows users the choice to update at their convenience, enhancing user experience while still ensuring app freshness.
- None:: This update type is designed for situations where no immediate action is required from the user.
🌟 Why Choose App Upgrader? #
- Staged Deployment Compatibility: Seamlessly manage staged deployments. Our suite avoids the common problem of endless update cycles by intelligently handling different app versions offered in app stores.
- Version History:: It allows the application to be updated according to the update types in the version history. For example, it checks the version date when updating an application that has not been updated for a long time even though the last version requires a flexible update. If there is a force update in intermediate versions, it is forced to force update. Thus, application security is maximised. (scenarios was inspired by bugragny. Thank you for your contributions!)
- Local Testing Support: Unlike other packages, App Upgrader allows comprehensive local testing, streamlining your development and logging processes. In
iOS
dev mode orAndroid
release mode, you can test your application locally by logging it with Alice or any logger.
App Upgrader is your go-to solution for a hassle-free app update experience.
🔥🔥🔥 Basic Usage 🔥🔥🔥 #
Here's a quick example to get you started with App Upgrader:
return MaterialApp(
//..
home: AppUpgrader(
bundleId: 'com.example.app',
versionInfoFetcher: MyVersionInfoFetcher(),
child: const MyHomePage(title: 'App Upgrader Prod App')),
);
Usage with go_router #
Integrating with navigation frameworks like go_router is straightforward:
GlobalKey<NavigatorState> navigatorKey = GlobalKey();
return MaterialApp.router(
routerConfig: routerConfig,
key: routerConfig.configuration.navigatorKey,
title: 'App Upgrader App go_router',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
builder: (context, child) {
return AppUpgrader(
navigatorKey: routerConfig.routerDelegate.navigatorKey,
bundleId: 'com.example.app',
versionInfoFetcher: MyVersionInfoFetcher(),
child: child ?? Containter(),
);
},
);
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.
To use
AppUpgrader
, you need to provide version information from a service such as Firebase Remote Config or a custom backend service. This should include JSON data for both Android and iOS platforms under keys likeandroid_version_info
andios_version_info
.
Example JSON for Android (android_version_info
):
{
// key should be build number of Android App
"210": {"update_type": "forceUpdate"},
"205": {"update_type": "none"},
// ... other versions ...
}
Example JSON for iOS (ios_version_info
):
{
// key should be version of iOS App
"4.8.8": {"update_type": "forceUpdate"},
"4.8.7": {"update_type": "none"},
// ... other versions ...
}
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',
- logger: An abstract class for logging purposes throughout the AppUpgrade process. Useful for logging and testing, especially in local environments.
import 'package:app_upgrader/app_upgrader.dart';
import 'package:alice/alice.dart';
class MyAppUpgradeLogger implements AppUpgradeLogger {
static Alice alice;
@override
void log(String message) {
alice = Alice(navigatorKey: rootNavigatorKey, showNotification: false);
alice.addLog(AliceLog(
message: message,
timestamp: DateTime.now(),
level: DiagnosticLevel.info));
}
}
- 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;
}
}
- localizationMessages: App Upgrader uses platform localization by default and localizationMessages is an optional parameter used to localize the text in the app update dialogs. By providing a LocalizationMessages instance, you can display messages in your desired language. This feature is particularly useful for applications targeting a global audience or specific regions.
Basic Usage with Default Localization:
localizationMessages: LocalizationMessages(code: 'en'), // English localization
Custom Localization Example: Suppose you want to provide custom messages in French. You would extend the LocalizationMessages class and implement the message logic based on the AppUpgraderMessage key.
class CustomFrenchMessages extends LocalizationMessages {
@override
String message({required AppUpgraderMessage messageKey, BuildContext? context}) {
switch (messageKey) {
case AppUpgraderMessage.title:
return 'Mise à jour disponible'; // Custom title in French
case AppUpgraderMessage.body:
return 'Une nouvelle version est disponible.'; // Custom body message
// ... handle other cases
default:
return super.message(messageKey: messageKey, context: context);
}
}
}
localizationMessages: CustomFrenchMessages(), // Your custom French localization
)
- 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!