How to get the app version in Flutter?

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.

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.

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

Share:

Ambika Dulal is a Flutter developer from Nepal who is passionate about building beautiful and user-friendly apps. She is always looking for new challenges and is eager to learn new things. She is also a strong believer in giving back to the community and is always willing to help others.

Leave a Comment

AO Logo

App Override is a leading mobile app development company based in Kathmandu, Nepal. Specializing in both Android and iOS app development, the company has established a strong reputation for delivering high-quality and innovative mobile solutions to clients across a range of industries.

Services

UI/UX Design

Custom App Development

Mobile Strategy Consulting

App Testing and Quality Assurance

App Maintenance and Support

App Marketing and Promotion

Contact

App Override

New Plaza, Kathmandu