Configure countryCode for iOS App Store
mainupgrader assumes the app is in the US App Store by default. If your app is distributed in a different country's App Store, you must provide the appropriate countryCode to the Upgrader instance.repository·main·Indexed 20 days ago
https://github.com/larryaasen/upgraderA Flutter package that prompts users to upgrade their application when a newer version is detected in the App Store or Google Play Store. It provides the UpgradeAlert widget for popup prompts (supporting Material and Cupertino styles) and the UpgradeCard widget for inline Material Design updates. The library supports custom Appcast XML feeds for remote version management, minimum version enforcement via store descriptions, and localization through the UpgraderMessages class.
upgrader assumes the app is in the US App Store by default. If your app is distributed in a different country's App Store, you must provide the appropriate countryCode to the Upgrader instance.The upgrader package uses the version package and follows the Semantic Versioning (SemVer) specification. It normalizes version strings to a 3-digit MAJOR.MINOR.PATCH format.
Requirement: Your version string in the Google Play or App Store listing must be a valid semantic version (e.g., 1.2.3 or 1.2.3+4). Formats like 1.2.3(4) are invalid and will cause a FormatException.
languageCode on the Upgrader instance to request the Google Play Store listing, description, and release notes in a specific language, provided a localized store page is available.To change the launch screen image for the iOS version of your application, you can use one of two methods:
example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory with your own assets.open ios/Runner.xcworkspace from your terminal.Runner/Assets.xcassets.open ios/Runner.xcworkspaceTo force an update and hide the 'Ignore' and 'Later' buttons in the UI, add the <sparkle:criticalUpdate /> tag within the <sparkle:tags> section of an item in your Appcast XML file.
<item>
<title>Version 1.15.0</title>
<sparkle:tags>
<sparkle:criticalUpdate />
</sparkle:tags>
...
</item>You can force users to update by adding specific text to your app's description field in the store. This overrides any minAppVersion parameter in code. When this text is present, the Ignore and Later buttons are automatically hidden.
[Minimum supported app version: 1.2.3] to the bottom of the full description.[:mav: 1.2.3] to the bottom of the description field in App Store Connect.When using the go_router package, you must provide the navigatorKey from your routerConfig to the UpgradeAlert widget. This ensures the upgrade dialog uses the correct route context.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Upgrader GoRouter Example',
routerConfig: routerConfig,
builder: (context, child) {
return UpgradeAlert(
navigatorKey: routerConfig.routerDelegate.navigatorKey,
child: child ?? const Text('child'),
);
},
);
}If your application uses CupertinoApp instead of MaterialApp, you can use the UpgradeAlert widget. However, note that UpgradeCard is not compatible with CupertinoApp because it relies on the Material Card widget.
To use UpgradeAlert in a Cupertino environment, set the dialogStyle to UpgradeDialogStyle.cupertino.
@override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Upgrader Example',
home: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Upgrader CupertinoApp Example'),
),
child: UpgradeAlert(
dialogStyle: UpgradeDialogStyle.cupertino,
child: const Center(child: Text('Checking...')),
),
),
);
}You can customize the text displayed in the alerts by extending the UpgraderMessages class. This allows you to:
message method to return localized strings for a specific languageCode.UpgraderMessages constructor.// Customizing a single string
class MyUpgraderMessages extends UpgraderMessages {
@override
String get buttonTitleIgnore => 'My Ignore';
}
// Implementing a full language
class MySpanishMessages extends UpgraderMessages {
@override
String message(UpgraderMessage messageKey) {
if (languageCode == 'es') {
switch (messageKey) {
case UpgraderMessage.body: return 'es A new version is available!';
case UpgraderMessage.buttonTitleIgnore: return 'es Ignore';
// ... other cases
default: break;
}
}
return super.message(messageKey);
}
}
// Usage
UpgradeAlert(upgrader: Upgrader(messages: MySpanishMessages()));
// Or forcing a language
UpgradeAlert(upgrader: Upgrader(messages: UpgraderMessages(code: 'es')));By default, the Android back button will not dismiss the UpgradeAlert dialog. To enable this behavior, use the shouldPopScope parameter and return true.
UpgradeAlert(shouldPopScope: () => true);The UpgradeAlert widget displays a popup alert prompt when a newer app version is detected. To use it, wrap your home widget with UpgradeAlert. Ensure UpgradeAlert is placed below MaterialApp in the widget tree.
By default, the alert includes three buttons:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Upgrader Example',
home: UpgradeAlert(
child: Scaffold(
appBar: AppBar(title: const Text('Upgrader Example')),
body: const Center(child: Text('Checking...')),
),
),
);
}
}upgrader logs. You can do this by setting the debugLogging property to true in your configuration. This will output detailed information regarding operating system, package info, locale, download URLs, and the internal decision-making process (e.g., isUpdateAvailable, shouldDisplayUpgrade).