Best practice for obtaining build number

Custom Code

I like to include my build number in my api requests so I can better track down bugs. In FlutterFlow, I believe there is no built-in way to access the build number of an app, so I am using package_info_plus 4.20 to obtain it (there is a newer version but FlutterFlow doesn't seem to support these versions yet).

Here is the custom Action I am using to obtain it:

import 'package:package_info_plus/package_info_plus.dart';

Future<int> appBuild() async {
  // Add your function code here!
  PackageInfo packageInfo = await PackageInfo.fromPlatform();
  int build = int.parse(packageInfo.buildNumber);

  FFAppState().build = build;
  return build;
}

I intend to store the build number in a non-persistent App State variable that I can access rather than calling this action repeatedly on time-sensitive actions like calling an API. I check to see if the build is set, and if not, call this function to set it. However, I'm finding that the build number isn't being reliably updated when the app is updated by TestFlight and sometimes the build number isn't being returned at all.

Is there a better way to accomplish what seems like it should be a much simpler task?

What have you tried so far?

I have tried the steps above

Did you check FlutterFlow's Documentation for this topic?
Yes
2
1 reply