DEV Community

Cover image for Force update in Flutter: in-app updates, minimum versions and OTA patches (with code)
Overpush
Overpush

Posted on

Force update in Flutter: in-app updates, minimum versions and OTA patches (with code)

You shipped a bug. You fixed it. Now the hard part: getting every user onto the fixed version.

"Force update" means different things depending on how urgent the fix is and what changed. This post covers four tools, from the gentlest to the most direct, with working code for each:

  1. A soft "update available" prompt
  2. Android in-app updates
  3. A minimum supported version (a hard force update)
  4. An over-the-air patch, so users never have to update at all

At the end there's a table to help you pick.


1. Soft prompt: "A new version is available"

Good for: normal releases you'd like people to install soon.

The upgrader package checks the store listing and shows a dialog when a newer version exists.

dependencies:
  upgrader: ^11.0.0
Enter fullscreen mode Exit fullscreen mode
import 'package:upgrader/upgrader.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: UpgradeAlert(
        child: const HomeScreen(),
      ),
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

The user can say "Later", which is the point: it's a nudge, not a requirement.


2. Android in-app updates

Good for: Android users who installed from Google Play.

Google Play has a built-in update flow. The in_app_update package exposes it to Flutter. There are two modes:

  • Immediate: a full-screen flow. The user updates before going back to the app.
  • Flexible: the download happens in the background while the app keeps running.
import 'package:in_app_update/in_app_update.dart';

Future<void> checkPlayUpdate() async {
  final info = await InAppUpdate.checkForUpdate();
  if (info.updateAvailability != UpdateAvailability.updateAvailable) return;

  if (info.immediateUpdateAllowed) {
    await InAppUpdate.performImmediateUpdate();
  } else if (info.flexibleUpdateAllowed) {
    await InAppUpdate.startFlexibleUpdate();
    await InAppUpdate.completeFlexibleUpdate();
  }
}
Enter fullscreen mode Exit fullscreen mode

Two things to know:

  • It only works for builds installed from Google Play. In debug builds, or apps installed with flutter run, it reports no update.
  • There is no iOS equivalent. On iOS you can only send people to the App Store page.

3. Minimum supported version (hard force update)

Good for: a version that is actually broken, such as a payment bug, a security issue, or an API you're shutting down.

The idea: keep a min_version value somewhere you control, and block the app if it's older. Firebase Remote Config works well for this, because you can change the value without shipping anything.

dependencies:
  firebase_remote_config: ^5.0.0
  package_info_plus: ^8.0.0
  url_launcher: ^6.3.0
Enter fullscreen mode Exit fullscreen mode
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:package_info_plus/package_info_plus.dart';

/// true when [current] is older than [minimum], e.g. 1.4.2 < 1.5.0
bool isOlder(String current, String minimum) {
  List<int> parts(String v) =>
      v.split('+').first.split('.').map((p) => int.tryParse(p) ?? 0).toList();
  final a = parts(current), b = parts(minimum);
  for (var i = 0; i < 3; i++) {
    final x = i < a.length ? a[i] : 0;
    final y = i < b.length ? b[i] : 0;
    if (x != y) return x < y;
  }
  return false;
}

Future<bool> mustUpdate() async {
  final rc = FirebaseRemoteConfig.instance;
  await rc.setConfigSettings(RemoteConfigSettings(
    fetchTimeout: const Duration(seconds: 10),
    minimumFetchInterval: const Duration(hours: 1),
  ));
  await rc.setDefaults({'min_version': '0.0.0'});
  try {
    await rc.fetchAndActivate();
  } catch (_) {
    return false; // offline: never lock people out because of the network
  }
  final info = await PackageInfo.fromPlatform();
  return isOlder(info.version, rc.getString('min_version'));
}
Enter fullscreen mode Exit fullscreen mode

Then show a blocking screen with a button to the store:

import 'dart:io';
import 'package:url_launcher/url_launcher.dart';

class UpdateRequiredScreen extends StatelessWidget {
  const UpdateRequiredScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final storeUrl = Platform.isIOS
        ? 'https://apps.apple.com/app/id0000000000'
        : 'https://play.google.com/store/apps/details?id=com.example.app';
    return Scaffold(
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(24),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Text('Please update to continue',
                  style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
              const SizedBox(height: 12),
              const Text('This version has a problem we have already fixed.'),
              const SizedBox(height: 24),
              FilledButton(
                onPressed: () => launchUrl(Uri.parse(storeUrl),
                    mode: LaunchMode.externalApplication),
                child: const Text('Update now'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

Use this sparingly. A blocking screen is a bad experience, and it only works once the fixed version has passed review and is live in the store.


The catch with all three

Every option above still needs:

  1. a new build,
  2. store review (a few hours on a good day, sometimes several days), and
  3. the user to actually install the update.

For a one-line bug fix, that's a lot of waiting while every user keeps hitting the bug.


4. Over-the-air patch: users don't update at all

Good for: bugs in your Dart code that need to be fixed now.

With an over-the-air (OTA) patch, the fix goes to the app that's already installed. OverPush does this for Flutter on Android and iOS.

One-time setup:

flutter pub add overpush
overpush init
overpush release android   # or: overpush release ios
Enter fullscreen mode Exit fullscreen mode

You ship that release to the store as usual. Later, when a bug shows up, you fix the Dart code and run:

overpush patch android     # or: overpush patch ios
Enter fullscreen mode Exit fullscreen mode

Users get the fix the next time they open the app. There's no prompt, no store visit, and no review wait.

You don't have to send it to everyone at once:

overpush patch ios --rollout-percent 10    # start with 10% of users
overpush patches rollout 1 --percent 100   # then everyone
Enter fullscreen mode Exit fullscreen mode

If you'd like to tell users that a fix is on the way, the package exposes events you can show in your own UI. See Show an "update ready" banner in your Flutter app.


Which one should you use?

Situation Best tool
Regular release, nothing urgent Soft prompt (upgrader)
Android users, want a smoother update In-app updates (in_app_update)
An old version must stop working (security, API shutdown) Minimum version + blocking screen
A bug in your Dart code that needs fixing today OTA patch (overpush patch)

They work well together: an OTA patch fixes today's bug, and a minimum version retires really old builds.


If you've built your own force-update flow, I'd love to hear how you handle it in the comments.

Top comments (0)