upgrader

repository·main·Indexed 20 days ago

https://github.com/larryaasen/upgrader

A 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.

Tokens
9.9K
Snippets
30
Records
45
Agent score
71%

What's inside upgrader

  1. Configure countryCode for iOS App Store

    main
    On iOS, 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.
  2. Semantic Versioning requirements

    main

    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.

  3. Configure languageCode for Android Store listings

    main
    On Android, you can set the 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.
  4. Customize the iOS launch screen assets

    main

    To change the launch screen image for the iOS version of your application, you can use one of two methods:

    1. Direct File Replacement: Replace the existing image files located in the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory with your own assets.
    2. Xcode Asset Catalog:
      • Open the iOS project in Xcode by running open ios/Runner.xcworkspace from your terminal.
      • In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
      • Drag and drop your desired images into the asset catalog to replace the defaults.
    open ios/Runner.xcworkspace
  5. Force a critical update via Appcast

    main

    To 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>
  6. Enforce a minimum app version via App Store descriptions

    main

    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.

    • Android (Google Play Store): Add [Minimum supported app version: 1.2.3] to the bottom of the full description.
    • iOS (App Store): Add [:mav: 1.2.3] to the bottom of the description field in App Store Connect.
  7. Integrate Upgrader with GoRouter

    main

    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'),
          );
        },
      );
    }
  8. Use UpgradeAlert with CupertinoApp

    main

    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...')),
            ),
          ),
        );
      }
  9. Customize Upgrader strings and localization

    main

    You can customize the text displayed in the alerts by extending the UpgraderMessages class. This allows you to:

    1. Override specific strings: e.g., changing the 'Ignore' button text.
    2. Add new languages: Implement the message method to return localized strings for a specific languageCode.
    3. Force a language: Pass a specific language code to the 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')));
  10. Allow Android back button to dismiss UpgradeAlert

    main

    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);
  11. Install and use UpgradeAlert for popup prompts

    main

    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:

    • IGNORE: Prevents the alert from being displayed again for the current version.
    • LATER: Closes the alert, allowing it to be displayed again in the future.
    • UPDATE NOW: Redirects the user to the App Store (iOS) or Google Play Store (Android) to initiate the update.
    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...')),
            ),
          ),
        );
      }
    }
  12. Enable debug logging for troubleshooting

    main
    When reporting issues, it is highly recommended to enable full 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).