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

Add support for deferred components #576

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ianmaciel
Copy link

@ianmaciel ianmaciel commented Sep 17, 2024

What does this change?

This PR include support for Flutter Deferred Components.

Deferred components allow developers to the app into multiple apk to reduce its size. This can be used to optimize the initial download and download components only on necessary but it is also mandatory for apk with more than 200MB.

This library initially looks for assets listed on flutter.assets of pubspec.yaml, with this change the library will continue looking for the assets lists under flutter.assets but will merge with the list of assets included on flutter.deferred-components.$. This will be merged in a single list.

Ideally in the future assets should have different classname, so users will easily know when dealing with deferred components. This wasn't implemented at this moment because it would requeire a significative changes.

Fixes #577 🎯

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
    • Ensure the tests (melos run test)
    • Ensure the analyzer and formatter pass (melos run format to automatically apply formatting)
  • Appropriate docs were updated (if necessary)

@ianmaciel ianmaciel marked this pull request as ready for review September 17, 2024 00:31
CHANGELOG.md Outdated Show resolved Hide resolved
});

// Merge the deferred assets with the main assets.
return [...config.pubspec.flutter.assets, ...deferredAssets];
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't [...?config.pubspec.flutter.deferredAssets?.assets] do the same thing as above?

Copy link
Author

@ianmaciel ianmaciel Sep 26, 2024

Choose a reason for hiding this comment

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

That's true...! good catch!
I actually don't need the forEach loop, just need to merge the two lists.

BTW, do you mean?

image

Copy link
Member

Choose a reason for hiding this comment

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

Yeah exactly

Copy link
Author

Choose a reason for hiding this comment

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

I'm sorry. For a moment I thought it was the same but it is not. I need to revert it.

The fact is we may have many Deferret Components, with many assets each (a list of lists).

So before spreading the list of deferredComponents, it is necessary to spread the assets from each deferredComponent

Copy link
Member

Choose a reason for hiding this comment

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

So you may reduce components' assets into one?

Copy link
Author

Choose a reason for hiding this comment

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

I didn't get that. 🤔
What do you mean by reduce components assets?

Copy link
Member

Choose a reason for hiding this comment

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

Something like reduce((list, assets) => list + assets)

Copy link
Author

Choose a reason for hiding this comment

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

I belive I'd need to use fold instead of reduce to have an initial empty list (I might have nothing at this point):
So I got something like this:
image

Copy link
Author

Choose a reason for hiding this comment

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

any thoughts?

packages/core/lib/settings/pubspec.dart Show resolved Hide resolved
@AlexV525
Copy link
Member

Also we need a test to make sure it works well

@ianmaciel
Copy link
Author

ianmaciel commented Sep 26, 2024

Hi @AlexV525,
I'm sorry about the late response. I couldn't get back to this before.

I pushed fixups for this pr, if this is okay please let me know so can rebase squashing those fixups.

@AlexV525
Copy link
Member

AlexV525 commented Oct 1, 2024

Changes are good but still missing tests. You don't need to squash them as we'll squash them to commit eventually.

@ianmaciel ianmaciel force-pushed the feature/add-support-for-deferred-components branch from 859d10e to 564f01b Compare October 15, 2024 18:42
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.

[FR]: Support deferred components
2 participants