Skip to content

Commit 694cec2

Browse files
committed
Add dart-define-from-file build arg example
1 parent b7beaf8 commit 694cec2

File tree

9 files changed

+41
-30
lines changed

9 files changed

+41
-30
lines changed

examples/hello_world/distribute_options.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
output: dist/
22
variables:
3-
FLUTTER_ROOT: ~/fvm/versions/3.10.0
3+
FLUTTER_ROOT: ~/fvm/versions/3.10.3
44
# PGYER_API_KEY: your api key
55
releases:
66
- name: dev-profile
@@ -79,7 +79,7 @@ releases:
7979
jobs:
8080
- name: android-aab
8181
variables:
82-
FLUTTER_ROOT: ~/fvm/versions/3.10.2
82+
FLUTTER_ROOT: ~/fvm/versions/3.10.3
8383
package:
8484
platform: android
8585
target: aab
@@ -113,6 +113,8 @@ releases:
113113
package:
114114
platform: macos
115115
target: dmg
116+
build_args:
117+
dart-define-from-file: env.json
116118
- name: macos-pkg
117119
package:
118120
platform: macos

examples/hello_world/env.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"APP_ENV": "dev"
3+
}

examples/hello_world/lib/main.dart

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class MyHomePage extends StatefulWidget {
5050
class _MyHomePageState extends State<MyHomePage> {
5151
int _counter = 0;
5252

53+
String get _appEnv {
54+
return const String.fromEnvironment('APP_ENV');
55+
}
56+
5357
String get _buildName {
5458
return const String.fromEnvironment('FLUTTER_BUILD_NAME');
5559
}
@@ -110,6 +114,10 @@ class _MyHomePageState extends State<MyHomePage> {
110114
'$_counter',
111115
style: Theme.of(context).textTheme.headlineMedium,
112116
),
117+
Text(
118+
'APP_ENV: $_appEnv',
119+
style: Theme.of(context).textTheme.bodyMedium,
120+
),
113121
Text(
114122
'FLUTTER_BUILD_NAME: $_buildName',
115123
style: Theme.of(context).textTheme.bodyMedium,

examples/hello_world/pubspec.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ packages:
4545
dependency: "direct main"
4646
description:
4747
name: cupertino_icons
48-
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
48+
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
4949
url: "https://pub.dev"
5050
source: hosted
51-
version: "1.0.5"
51+
version: "1.0.6"
5252
fake_async:
5353
dependency: transitive
5454
description:
@@ -66,10 +66,10 @@ packages:
6666
dependency: "direct dev"
6767
description:
6868
name: flutter_lints
69-
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
69+
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
7070
url: "https://pub.dev"
7171
source: hosted
72-
version: "2.0.1"
72+
version: "2.0.3"
7373
flutter_test:
7474
dependency: "direct dev"
7575
description: flutter

packages/flutter_app_builder/lib/src/builders/app_builder.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ abstract class AppBuilder {
6565
);
6666

6767
if (processResult.exitCode != 0) {
68-
throw BuildError();
68+
throw BuildError('${processResult.stderr}');
6969
}
7070

7171
return resultResolver.resolve(config)..duration = time.elapsed;

packages/flutter_app_builder/lib/src/commands/flutter.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,20 @@ class _Flutter extends Command {
5656
String flutterRoot = environment?['FLUTTER_ROOT'] ?? '';
5757
if (flutterRoot.isNotEmpty) {
5858
flutterRoot = pathExpansion(flutterRoot, environment ?? {});
59+
if (!Directory(flutterRoot).existsSync()) {
60+
throw CommandError(
61+
this,
62+
'FLUTTER_ROOT environment variable is set to a path that does not exist: $flutterRoot',
63+
);
64+
}
5965
return p.join(flutterRoot, 'bin', 'flutter');
6066
}
6167
return 'flutter';
6268
}
6369

6470
Map<String, String>? environment;
6571

66-
withEnv(Map<String, String>? environment) {
72+
_Flutter withEnv(Map<String, String>? environment) {
6773
this.environment = environment;
6874
return this;
6975
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library shell_executor;
22

33
export 'src/command.dart';
4+
export 'src/command_error.dart';
45
export 'src/shell_executor.dart';
56
export 'src/utils/path_expansion.dart';

packages/shell_executor/lib/src/command.dart

-22
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,4 @@ abstract class Command {
3030
runInShell: runInShell,
3131
);
3232
}
33-
34-
Future<ProcessResult> run(
35-
List<String> arguments, {
36-
Map<String, String>? environment,
37-
}) {
38-
return exec(
39-
arguments,
40-
environment: environment,
41-
);
42-
}
43-
44-
ProcessResult runSync(
45-
List<String> arguments, {
46-
Map<String, String>? environment,
47-
bool runInShell = false,
48-
}) {
49-
return execSync(
50-
arguments,
51-
environment: environment,
52-
runInShell: runInShell,
53-
);
54-
}
5533
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:shell_executor/src/command.dart';
2+
3+
class CommandError extends Error {
4+
CommandError(this.command, [this.message]);
5+
6+
final Command command;
7+
final String? message;
8+
9+
@override
10+
String toString() {
11+
return (message != null) ? 'CommandError: $message' : 'CommandError';
12+
}
13+
}

0 commit comments

Comments
 (0)