How to get build and version number of Flutter app

Cover Image for How to get build and version number of Flutter app
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

How to Get Build and Version Number of a Flutter App

šŸ“± Are you developing an awesome Flutter app? šŸš€ Do you want to display the build and version number to your users? šŸ·ļø No worries, we got you covered! In this guide, we'll walk you through the steps to get the build and version number of your Flutter app.

The Challenge

āš ļø Imagine you're developing an app in beta mode and want to show your users the version they are currently on. For example, "v1.0b10 - iOS". You've already tried using the code Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android")), but you still need to fetch the actual build version and number dynamically.

The Solution

āœ… To solve this challenge, we'll use the package called package_info. This package provides access to various information about the application, including the version number and build number.

šŸ’” Here are the easy steps to get the build and version number of your Flutter app:

  1. Add the package_info dependency to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  package_info: ^2.0.3
  1. Run flutter pub get to fetch the dependency.

  2. Import the package_info package in your Dart file:

import 'package:package_info/package_info.dart';
  1. Get the build and version numbers using the PackageInfo class:

PackageInfo packageInfo = await PackageInfo.fromPlatform();
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
  1. Use the obtained version and buildNumber variables wherever you want to display the information in your app:

Text("Build: ${version}b${buildNumber} - ${Platform.isIOS ? "iOS" : "Android"}")
// Example output: "Build: v1.0b10 - iOS"

That's it! šŸŽ‰ You will now be able to display the actual build and version number dynamically in your Flutter app.

Call-to-Action

šŸ“£ Now that you know how to get the build and version number of your Flutter app, go ahead and implement it in your project! šŸš€ Show your users that you care about providing them the latest updates and improvements. šŸ˜Š

ā“ Do you have more questions or encountered any issues along the way? Let us know in the comments section below! Our amazing community is always here to help you out. šŸ¤

šŸ‘‰ Don't forget to share this blog post with your fellow Flutter developers! Sharing is caring. ā¤ļø

Happy coding! šŸ’»āœØ


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

šŸ”„ šŸ’» šŸ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! šŸš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings šŸ’„āœ‚ļø Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide šŸš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? šŸ¤” Well, my

Matheus Mello
Matheus Mello