Keeping Your Flutter App Up to Date with upgrader

As a developer, ensuring that your users are running the latest version of your app is crucial. However, relying on store alerts alone may not be enough, especially if you’re following a release early, release often philosophy. In this article, we’ll explore how to use the upgrader plugin to alert users and prompt them to update their app to the newest version.

Why Use upgrader?

Version fragmentation can occur when there are too many versions of an app in the market, leading to expensive business operations. upgrader helps reduce the impact of version fragmentation by:

  • Providing a manageable list of versions that you support
  • Enforcing a minimum version you are supporting
  • Guiding the user through updates if their app is not running the latest version

Getting Started

To follow along with this guide, you should have basic knowledge of Flutter, stateful widgets, and package versioning. You’ll also need a working knowledge of pushing mobile apps to the Google Play Store and Apple App Store.

We’ll be using the Days Without Incidents (DWI) app to demonstrate concepts. Download the open-source code via GitHub and ensure you’re using Flutter v3.0+. Open the project with your preferred IDE, and remember to get the dependencies with flutter pub get.

Understanding how upgrader Works

upgrader is a Flutter plugin that helps manage the user’s installed version of your app. It allows you to check if the user has the latest version installed and guides the user to install it via an app store with a dialog or widget.

Displaying Alerts if the App is Outdated

One of the most common use cases for upgrader is to display a dialog box when the currently installed app is outdated compared to the store listing. To try this out, open the lib/features/time_counter/pages/counter_page.dart file and change the CountersPage build to the following:

dart
UpgradeAlert(
child: Scaffold(
appBar: AppBar(
title: Text('Days Without Incidents'),
),
body: Center(
child: Text('Hello, World!'),
),
),
)

Implementing Custom Upgrade Widgets

Sometimes, the built-in behaviors (UpgradeAlert and UpgradeCard) are not enough in terms of user experience. For example, you may want to show an IconButton when there’s an update available for the app. Let’s create a custom widget that will work like UpgradeAlert and UpgradeCard.

Create a new file called upgrade_widget.dart and add the following code:

“`dart
import ‘package:flutter/material.dart’;
import ‘package:upgrader/upgrader.dart’;

class UpgradeWidget extends StatelessWidget {
final Widget child;

UpgradeWidget({required this.child});

@override
Widget build(BuildContext context) {
return UpgradeBase(
child: child,
builder: (context, upgrader) {
return ElevatedButton(
onPressed: () async {
await upgrader.checkVersion(context);
},
child: Text(‘Update’),
);
},
);
}
}
“`

Enforcing a Minimum Version in the App

Another great feature of upgrader is its ability to enforce a minimum app version simply by adding predefined text to the description in the app stores or by defining a minimum app version inside Upgrader.

Controlling Your Own Version Listings

An important limit of upgrader is that its default behavior leverages the current Apple App Store and Google Play Store listings of your app. To solve this, upgrader offers support for working with Appcast, which is based on the Sparkle framework.

By following these steps and using the upgrader plugin, you can keep your users running the latest version of your app and reduce the impact of version fragmentation.

Leave a Reply

Your email address will not be published. Required fields are marked *