Flutter Tutorials

How to Get the App Version in Flutter?

· · Updated April 12, 2024
app version

By the end of this tutorial, you’ll know how to get the app version in Flutter, providing a personalized touch to your Flutter app’s version management. Let’s dive into the details.

This blog post will guide you through creating a robust versioning system in your Flutter app based on a four-segment approach: Major, Release, Minor, and Daily.

You can follow the official documentation to set up Flutter: Flutter Installation Guide.

Table of Contents

Introduction to App Version in Flutter

In the dynamic world of app development, effective versioning is crucial for seamless communication, deployment, and debugging.

For Flutter developers, understanding how to retrieve and manage version numbers is essential.

This versioning system allows you to easily track major milestones (Major), market releases (Release), incremental changes (Minor), and the daily progress or builds (Daily) of your application.

It provides a structured approach to versioning that can help in communication, debugging, and tracking the development life cycle of your software.

How to get the app version in Flutter?

1. Major Version

In Flutter, the major version is a constant value representing a significant milestone or major update. In your pubspec.yaml file, set the major version as follows:

version: 3.18.0+1

Here, ‘3’ is the Major version, and it remains constant until a major overhaul is introduced.

  • Fixed value of 3.
  • Indicates a major milestone or significant release of your application.
  • This number won’t change frequently and is likely to be updated only for major updates or overhauls.

2. Release Version

The release version represents the version released to different markets. It changes upon uploading your app to various platforms. Update the release version as follows:

import 'package:flutter/services.dart' show rootBundle;

Future<String> getReleaseVersion() async {
  final contents = await rootBundle.loadString('pubspec.yaml');
  final lines = contents.split('\n');
  
  for (var line in lines) {
    if (line.startsWith('version:')) {
      final version = line.split(':')[1].trim();
      return version;
    }
  }
  return 'Error: Version not found';
}

This function extracts the version from the pubspec.yaml file, giving you the current release version.

  • Initial value of 18.
  • Represents the version released to different markets.
  • You increment this number each time you upload a new version to the various app markets (e.g., Apple App Store, Google Play Store).
  • Changing the release version is usually associated with a broader deployment or distribution event.

3. Minor Version

For the minor version, update it at the end of each sprint. In your CI/CD pipeline or manual process, modify the version in pubspec.yaml:

version: 3.19.0+1

This incremental change indicates the introduction of new features or improvements at the end of each development sprint.

  • To be changed at the end of every sprint.
  • Reflects incremental changes or features added during a development sprint.
  • Typically updated more frequently than the release version, indicating smaller updates made within a development cycle.

4. Daily Version

The daily version represents the build number, updated with every build composition. To implement this, consider using a CI/CD tool or a script to automate the process. Update the version in pubspec.yaml as follows:

version: 3.19.0+2

This way, the daily version reflects the constant evolution of your app during the development phase.

Attraction of app version in Flutter

  • Updated every time a new build is composed.
  • Represents daily or more frequent builds of the application during the development process.
  • This allows for a finer-grained versioning system, helping to track progress and changes daily

Also, Read Related Tutorials

Conclusion

By adopting this four-segment versioning approach in your Flutter app, you establish a structured and meaningful system. It simplifies communication, aids in debugging, and facilitates efficient deployment. Embrace versioning not just as a technicality, but as a powerful tool for managing the lifecycle of your app with confidence.

Ambika Dulal

About Ambika Dulal

Lead Mobile App Developer and Tech Consultant specializing in Flutter, Dart, and Firebase.