Skip to content

[proposal] allow to detect programmatically what flutter version the app was compiled under #61814

Closed

Description

@atreeon

Sometimes bugs in a Flutter app are dependent on which version of Flutter the code was compiled with. For this reason, it would be nice to have (or is there a way already) to find out programmatically what version of Flutter my app was compiled with.

Question on SO here: https://stackoverflow.com/questions/62958749

Activity

  1. iapicca commented on Jul 20, 2020

    @iapicca

    Hi @atreeon
    can I hijack your question as a feature request?
    I think this feature would be desirable especially on long term;
    wether it would be one line in the pubspec.yaml like created from: 1.17.5,
    or just a command to run in terminal.
    Thank you

  2. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 20, 2020
  3. atreeon commented on Jul 20, 2020

    @atreeon
    Author

    absolutely @iapicca , if its not possible now then adding this as a feature would be great. It would be great to get this programmatically. Something like Platform.version from dart:io that can be used to get the dart version (although that doesn't work in web) during runtime of the app to then show it on an aboutdialog page or something like that.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 20, 2020
  5. added
    c: proposalA detailed proposal for a change to Flutter
    c: new featureNothing broken; request for a new capability
    toolAffects the "flutter" command-line tool. See also t: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Jul 20, 2020
  6. changed the title [-]How do we programmatically find the flutter version the app was compiled under?[/-] [+][proposal] allow to detect programmatically what flutter version the app was compiled under[/+] on Jul 20, 2020
  7. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    and removed
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jul 21, 2020
  8. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    P3Issues that are less important to the Flutter project
    on Aug 16, 2022
  9. oboobortot commented on Jan 26, 2023

    @oboobortot

    Not a solution if you don't have flutter installed. Yet mentioning how you can get it on Dev Environments.

    I agree it will be best we can get this from the compiled output using introspection (but not mirrors).

    import 'dart:io' show Process;
    import 'dart:convert' show utf8;
    
    /// Get the Flutter and Dart versions, channel and revision.
    /// ```example
    /// Flutter 3.3.10 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 135454af32 (6 weeks ago) • 2022-12-15 07:36:55 -0800\nEngine • revision 3316dd8728\nTools • Dart 2.18.6 • DevTools 2.15.0\n
    /// ```
    Future<String> flutterVersion() async {
      final process = await Process.run(
        'flutter',
        ['--version'],
        stderrEncoding: utf8,
        stdoutEncoding: utf8,
      );
      if ((process.stdout as String).isNotEmpty) {
        return process.stdout as String;
      }
      return '';
    }
  10. markvideon commented on Mar 12, 2023

    @markvideon

    Not a solution if you don't have flutter installed. Yet mentioning how you can get it on Dev Environments.

    I agree it will be best we can get this from the compiled output using introspection (but not mirrors).

    import 'dart:io' show Process;
    import 'dart:convert' show utf8;
    
    /// Get the Flutter and Dart versions, channel and revision.
    /// ```example
    /// Flutter 3.3.10 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 135454af32 (6 weeks ago) • 2022-12-15 07:36:55 -0800\nEngine • revision 3316dd8728\nTools • Dart 2.18.6 • DevTools 2.15.0\n
    /// ```
    Future<String> flutterVersion() async {
      final process = await Process.run(
        'flutter',
        ['--version'],
        stderrEncoding: utf8,
        stdoutEncoding: utf8,
      );
      if ((process.stdout as String).isNotEmpty) {
        return process.stdout as String;
      }
      return '';
    }

    This would report the current version of the first available Flutter SDK in the system path, not the version an application was compiled with.

    I suppose it could be available as a string constant at runtime after being injected at compile time with some reserved keyword?

    e.g.
    const appVersion = String.fromEnvironemnt('FLUTTER_VERSION');

  11. ueman commented on Jan 1, 2024

    @ueman
    Contributor

    I think (maybe naively) this should be fairly easy to add:

    There's already code in the Flutter tool to access the appFlavor at runtime here

    if (flavor != null) {
    if (globals.platform.environment['FLUTTER_APP_FLAVOR'] != null) {
    throwToolExit('FLUTTER_APP_FLAVOR is used by the framework and cannot be set in the environment.');
    }
    if (dartDefines.any((String define) => define.startsWith('FLUTTER_APP_FLAVOR'))) {
    throwToolExit('FLUTTER_APP_FLAVOR is used by the framework and cannot be '
    'set using --${FlutterOptions.kDartDefinesOption} or --${FlutterOptions.kDartDefineFromFileOption}');
    }
    dartDefines.add('FLUTTER_APP_FLAVOR=$flavor');

    The same approach could be used to make the Flutter meta-data available to the app. In the Flutter tool, we know the Flutter version, channel and some other interesting information. It's available via globals.flutterVersion.

    See

    abstract class FlutterVersion {

    If that's an acceptable way of making it available at runtime to the app, I would attempt to create a PR.

  12. iamsergio commented on Jun 15, 2024

    @iamsergio

    In my build/deploy scripts I simply:

    FLUTTER_VERSION=`flutter --version | grep 'Flutter' | awk '{print $2}'`
    flutter build <other args> --dart-define=MY_APP_FLUTTER_VERSION=$FLUTTER_VERSION
    
  13. pro100svitlo commented on Jan 2, 2025

    @pro100svitlo

    Hi guys,

    Since I've faced a similar problem, I created a dart_flutter_version package that allows you to find out the version of the flutter used to build the program (with some accuracy).

    Please let me know what you think 🙏

  14. github-actions commented on Mar 6, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions