Display mobile app build number in app

Hi,

My app, once published, is built into iOS and Android mobile apps thanks to the native app mobile shell.

I am looking for a way to display, withing the app, the build number which features in the pubspec.yaml file.

How would you suggest to achieve this ?

Of course I could set it before publishing, but then if I end up creating several successive builds with the same published version, there will be discrepancies.

Is there a way for the app to read a local text file somewhere, whether within the uibuilder folder or even above it ?

Thanks

Hello, @Nicolas_REMY.

I don’t completely understand where you want to change the app version. In general as for me, I have changed the app version before release in pubspec.yaml, build.gradle(in app folder, for Android), and in Runner(for iOS).


Please explain what behavior you want to achieve.

Best Regards, Nikita.

Hi @Nikita_Fedorishchev,

Thanks for your reply and sorry for not being clear enough.

The app version and build numbers are fine in the pubspec.yaml file :
image

The thing is I would like to find a way for this information to be visible WITHIN the app.

Here is what I have achieved up to now :


At the bottom of the menu, you can see the version number being displayed.

I did this up to now by using a static function within the app :
image

However, this is not satisfactory because I need to remember to update it for each new version and keep it in sync with the pubspec.yaml file. And displaying the build number is even trickier, because I can build the mobile app several times with the same published web app.

So I am looking for a way for this display to get its information (version and build number) from the value in the pubspec.yaml file. Any ideas ?

I think link will be useful: How to get build and version number of Flutter app - Stack Overflow

After implementation of this you need to call native method in ui builder, and add implementation of your method in bridge_manager. Like this example, but with your own method name and implementation.

I will discuss this method with the team and maybe we will implement it into native shell. But at the moment you need to implement it yourself.
If you have any questions please let me know, Im happy to help you.

Best Regards, Nikita

1 Like

Hi @Nikita_Fedorishchev, sorry for coming back about this, but I haven’t managed to understand the whole thing.

I tried using either the package_info_plus or the package_info as described in the thread you pointed to, and then adding the code you provided.

However, currentState is unknown.

It seems there is a missing a link somewhere. Can you advise ?

Thanks.

Current state it’s just field in my example that used for my task.
For your case you need to write your own logic. I will write code for your requirements a bit later.

Best Regards, Nikita.

1.Add this code in pubspec.yaml:
package_info_plus: ^3.0.2

  1. Import this in bridge_manager.dart:
    import 'package:package_info_plus/package_info_plus.dart';

  2. Add field into class BridgeManager:
    static PackageInfo? info;

  3. This should be in switch case(bridge_manager.dart file):

        case _GET_CURRENT_VERSION:
          {
            if (info == null) {
              info = await PackageInfo.fromPlatform();
            }

            result = info!.version;
            return buildResponse(data: requestContainer, response: result);
          }

Codeless:

Result from print in codeless:
flutter: {message: 1.0.0, messageLevel: 1}

If you have any questions please let me know.

Best Regards, Nikita,

Hi @Nikita_Fedorishchev ,

I will only be able to test this once the EU cluster is back online.
However, when trying to implement it, I believe I found something missing in your steps above :

Shouldn’t there be

static const String _GET_CURRENT_VERSION = 'GET_CURRENT_VERSION';

in the beginning of class BridgeManager ?

Also, this returns the version number, but could you confirm that returning the build number, I would have to define a similar case with buildNumber as follows ?

        case _GET_CURRENT_BUILD_NUMBER:
          {
            if (info == null) {
              info = await PackageInfo.fromPlatform();
            }

            result = info!.buildNumber;
            return buildResponse(data: requestContainer, response: result);
          }

you need to do it in a similar way to this:
method name:

implementation:

You only need just copy/paste code that I described above.

Good news, looks like it’s working ! Thanks a lot for your help on this !

1 Like