Skip to content

[tool] Migrate CreateCommand to modular dependency injection - #190785

Merged
auto-submit[bot] merged 22 commits into
flutter:masterfrom
bkonyi:di/18-create
Sep 15, 2026
Merged

auto-submit[bot] merged 22 commits into
flutter:masterfrom
bkonyi:di/18-create

Conversation

@bkonyi

@bkonyi bkonyi commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 18 of the modular dependency injection migration.

  • Migrates CreateCommand, CreateBase, and WidgetPreviewCommand to modular constructor dependency injection with zero fallbacks:
    • CreateCommand({required ToolContext toolContext, required this.androidContext, required this.appleContext, ExtensionTemplateManager? extensionTemplateManager, required TemplateRenderer templateRenderer, bool verboseHelp = false})
    • WidgetPreviewCommand({required ShutdownHooks shutdownHooks, required ToolContext toolContext, required bool verboseHelp, ...})
  • Requires non-nullable context objects (ToolContext, AndroidContext, AppleContext) and TemplateRenderer, eliminating individual constructor fallback parameters and ambient globals.*.
  • Migrates unit tests in packages/flutter_tools/test/commands.shard/hermetic/create_usage_test.dart to hermetic testWithoutContext.

Part of #188471

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team labels Aug 8, 2026
@bkonyi
bkonyi force-pushed the di/18-create branch 7 times, most recently from 0ff277c to 49a9979 Compare August 12, 2026 18:39
@bkonyi
bkonyi marked this pull request as ready for review September 2, 2026 13:22
@bkonyi bkonyi added the CICD Run CI/CD label Sep 2, 2026
@github-actions github-actions Bot removed a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team labels Sep 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors CreateCommand and CreateBase to accept and use a ToolContext instead of accessing global variables directly, updating the command instantiation and associated tests accordingly. Feedback on the changes suggests making toolContext a required parameter in WidgetPreviewCommand, WidgetPreviewSubCommandBase, and WidgetPreviewStartCommand to enforce compile-time null safety and prevent potential runtime null assertion crashes.

Comment thread packages/flutter_tools/lib/src/commands/widget_preview.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/widget_preview.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/widget_preview.dart Outdated
@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors CreateCommand, WidgetPreviewCommand, and the CreateBase mixin to accept and utilize ToolContext for dependency injection, replacing references to global variables. Corresponding unit and integration tests are updated to supply a ToolContext during command instantiation. The review feedback suggests further simplifying the WidgetPreviewCommand constructor, its instantiation in executable.dart, and its test setup by removing redundant individual dependency parameters that can be directly extracted from the newly required ToolContext.

Comment thread packages/flutter_tools/lib/src/commands/widget_preview.dart Outdated
Comment thread packages/flutter_tools/lib/executable.dart Outdated
@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@bkonyi
bkonyi requested a review from chingjun September 9, 2026 16:33
@chingjun

Copy link
Copy Markdown
Contributor

Looks like the g3fix needs to be updated for this PR.

@bkonyi

bkonyi commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Looks like the g3fix needs to be updated for this PR.

Fixed now!

chingjun
chingjun previously approved these changes Sep 12, 2026

@dcharkes dcharkes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reapproving rebased+deps-bumped+formatted+linted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants