Skip to content

Commit

Permalink
Develop (#17)
Browse files Browse the repository at this point in the history
Propagate flutter version correctly to GetFlutterTask when running ProjectCreate.
  • Loading branch information
buijs-dev authored May 13, 2024
1 parent cac90eb commit 5e7de92
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/src/cli/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class Task<T> {
/// Execute the task and return instance of [T] or throw
/// [KlutterException] if unsuccessful.
Future<T> executeOrThrow(Context context) async {
return await toBeExecuted(context, _getOptions(context));
return toBeExecuted(context, _getOptions(context));
}

/// The validated options.
Expand Down
12 changes: 11 additions & 1 deletion lib/src/cli/task_project_create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ class CreateProject extends Task {
final dist = toFlutterDistributionOrThrow(
version: flutterVersion, pathToRoot: pathToRoot);

final result = await _getFlutterSDK.executeOrThrow(context);
final result =
await _getFlutterSDK.executeOrThrow(context.copyWith(taskOptions: {
TaskOption.flutter: dist.folderNameString.toString(),
}));

final flutter =
result.resolveFile("flutter/bin/flutter".normalize).absolutePath;
final root = await createFlutterProjectOrThrow(
Expand Down Expand Up @@ -136,6 +140,12 @@ class CreateProject extends Task {
TaskOption.lib: name,
}));

_executor
..workingDirectory = root
..arguments = ["klutterGetKradle", "-p", "platform"]
..executable = root.resolveFile("gradlew").absolutePath
..run();

exampleFolder
..deleteTestFolder
..deleteIntegrationTestFolder;
Expand Down
19 changes: 18 additions & 1 deletion test/src/cli/task_project_create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,28 @@ void main() {
expect(result.isOk, false);
expect(result.message, "BOOM!");
});

test("Verify flutter option is used correctly", () async {
const version = "3.0.5.macos.arm64";
final getFlutterTask = FlutterFixedVersion();
final task = CreateProject(getFlutterSDK: getFlutterTask);
final result = await task
.execute(Context(Directory.systemTemp, {TaskOption.flutter: version}));
expect(result.isOk, false);
expect(result.message, version);
});
}

class NoFlutterSDK extends GetFlutterSDK {
@override
Future<Directory> executeOrThrow(Context context) async {
throw KlutterException("BOOM!");
throw const KlutterException("BOOM!");
}
}

class FlutterFixedVersion extends GetFlutterSDK {
@override
Future<Directory> executeOrThrow(Context context) async {
throw KlutterException(context.taskOptions[TaskOption.flutter] ?? "--");
}
}

0 comments on commit 5e7de92

Please sign in to comment.