Add API to read flavor from framework at run time (#134179)

Resolves #128046.

Adds a services API that allows flutter app developers to write app code that determines `--flavor` the app was built with.

This is implemented by having the tool adding the value of `--flavor` to its list of dart environment declarations, which will be available to the app at run time. Specifically,`FLUTTER_APP_FLAVOR` is set. I chose this implementation for its simplicity. There is some precedent for this, but only for web ([example](cd2f3f5e78/packages/flutter_tools/lib/src/runner/flutter_command.dart (L1231))).
This commit is contained in:
Andrew Kolos
2023-09-28 10:38:54 -07:00
committed by GitHub
parent c35515a079
commit aa498cd51a
5 changed files with 109 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flavors/main.dart' as app;
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -16,6 +17,7 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('paid'), findsOneWidget);
expect(appFlavor, 'paid');
});
});
}