Compare app versions

Flutter tips Published on

Have you ever needed to check if a user is using an old version of your app? It's a common task, especially when you release updates.

Flutter makes this pretty straightforward with the help of a couple of handy packages.

How to Get and Compare Versions

First, you need to get the current version of your installed app. You can do this using the package_info_plus package. It provides details about your application.

Next, to compare versions properly, you'll use the version package. This package understands version numbers (like '1.0.1' or '2.40.1') and lets you compare them easily.

Example Code

Here’s a simple look at how you might put it together:

// get the current version installed using this
import 'package:package_info_plus/package_info_plus.dart';
// the Version package to compare versions
import 'package:version/version.dart';

Future<void> checkAppVersion(Version minVersion) async {
  final info = await PackageInfo.fromPlatform();
  final currentVersion = Version.parse(info.version);

  if (currentVersion < minVersion) {
    throw UpdateRequired(); // Or handle the old version as needed
  }
}

In this code snippet:

Get Package Info

We use PackageInfo.fromPlatform() to get details like the app's version number.

Parse the Version

The version number from package_info_plus is a string (like "1.0.1"). We use Version.parse() from the version package to turn this string into a special Version object that can be compared.

Compare Versions

The Version objects can be compared directly using operators like < (less than), > (greater than), == (equal to), etc. This is much easier and more reliable than comparing the version strings directly, as the version package handles different number parts correctly (e.g., it knows 2.0 is older than 2.1, and 2.1 is older than 2.10).

So, if the currentVersion is less than the minVersion you set, you know the user needs to update.

This approach is clean and effective for managing app updates and ensuring users are on a supported version.

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

How do I get the current app version in Flutter?

You can get the current app version using the `package_info_plus` package. Use `PackageInfo.fromPlatform()` to get app details, including the version.

How can I compare version numbers like 1.0.1 and 2.40.1?

You can use the `version` package. Parse the version strings into `Version` objects using `Version.parse()`, and then compare these objects directly using operators like `<`, `>`, or `==`.

Which packages are needed to compare app versions?

You typically need the `package_info_plus` package to get the current app version string and the `version` package to parse and compare the version numbers correctly.

Read more
You may also be interested in
Flutter tips: some useful date extension methods  blog card image
Flutter tips: some useful date extension methods
Published on 2025-05-04
Guide Users Easily: Tutorial Overlays in Flutter with pal_widgets  blog card image
Guide Users Easily: Tutorial Overlays in Flutter with pal_widgets
Published on 2025-05-12T08:10:13.136Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved