Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize Flutter bootstrap code #2969

Merged
merged 1 commit into from
May 29, 2024
Merged

Standardize Flutter bootstrap code #2969

merged 1 commit into from
May 29, 2024

Conversation

parlough
Copy link
Member

Closes #2966

@daohoangson
Copy link

I would love to see PR merged. At the moment, registerPlugins is being called before bootstrapEngine, which is causing issues with package_info_plus. That plugin needs the asset manager during registration.

daohoangson added a commit to flutter-widget-from-html/try that referenced this pull request May 20, 2024
This is a workaround until dart-lang#2969 is merged
@parlough
Copy link
Member Author

@daohoangson Could you provide more details on the issue you're seeing or where? I don't believe package: package_info_plus is supported in DartPad.

@daohoangson
Copy link

daohoangson commented May 20, 2024

Sorry for not being clear, I have been maintaining my own version of DartPad with additional packages. The build starts failing after adding package_info_plus so I tried to debug it.

The plugin tries to get the asset manager:

https://github.com/fluttercommunity/plus_plugins/blob/c71730e65a0ea59bc177d3dcb2da2abbaa1bcc61/packages/package_info_plus/package_info_plus/lib/src/package_info_plus_web.dart#L20

_assetManager = assetManagerMock ?? assetManager;

The getter looks like this:

https://github.com/flutter/engine/blob/c6fecf65fbf385c5e9168c5b40526c9ae998045b/lib/web_ui/lib/ui_web/src/ui_web/asset_manager.dart#L11

AssetManager get assetManager => engineAssetManager;

It calls another getter:

https://github.com/flutter/engine/blob/c6fecf65fbf385c5e9168c5b40526c9ae998045b/lib/web_ui/lib/src/engine/initialization.dart#L242

ui_web.AssetManager get engineAssetManager => _debugAssetManager ?? _assetManager!;

Because registerPlugins was called before bootstrapEngine, _assetManager is null so the ! operator throws an error.

@parlough parlough marked this pull request as ready for review May 20, 2024 19:45
@parlough parlough requested a review from johnpryan May 20, 2024 19:45
await ui_web.bootstrapEngine(
runApp: () {
return entrypoint.main();
entrypoint.main();
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

What does this change do?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it... We might not need to maintain this code any more. The comment above is old and out of date since flutter/flutter#144434 landed and we integrated the new bootstrapping (#2960)

@johnpryan
Copy link
Contributor

johnpryan commented May 29, 2024

Do we even need to call registerPlugins anymore? I think we might be able to remove kBootstrapFlutterCode and rely on the new bootstrapping improvements to initialize plugins.

cc: @eyebrowsoffire @ditman

@johnpryan johnpryan merged commit e93bae9 into main May 29, 2024
6 checks passed
@johnpryan johnpryan deleted the misc/bootstrap-cleanup branch May 29, 2024 17:09
@ditman
Copy link
Member

ditman commented May 29, 2024

@johnpryan I don't remember dartpad code very well, but I think the new bootstrapping code is NOT generating the actual main.dart file that contains the registerPlugins call, it's done by the flutter tool here:

https://github.com/flutter/flutter/blob/main/packages/flutter_tools/lib/src/web/file_generators/main_dart.dart

That generated file is the thing that glues the framework + engine + plugins + user code, so users only have to worry about writing the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Future<void> main() async ... fails on dartpad if flutter is imported
6 participants