How to Get the App Version/Build Number in Flutter
I was building an About page in my Flutter app today and was wondering how to get and display the app version number. A couple google searches and Flutter reloads later, I found out how to do it using the package_info plugin. Here's how.
Add the package_info package to your Flutter project by listing the former as a dependency in your pubspec.yaml as below. Protip, use Pubspec Assist to speed this up.
2. Import package_info in the file where you'll be needing the version file.
3. Write an async function that will return the version number (or whatever else you need; you can get the build number, your app name, or package name):
4. As the version number will be loaded asynchronously, use a FutureBuilder together with a Text widget (or any other widget of your choice):
5. In my case, I wrapped the text in a disabled ListTile, so that I could place it inside a settings page. Full Example:
That's it! Your page will look somewhat like this:
Thanks for reading. If you have any questions, drop them below. Hope this helped!
Let's keep in touch
Subscribe and I'll let you know when I post. No spam, I promise.