flutter / flutter/flutter

RemoteFlutterWidgets: Make Icon optional to enable tree shaking

Open
#182,724 1 comment 2 reactions 0 assignees View on GitHub
c: new feature c: proposal p: rfw P3 package team-ecosystem triaged-ecosystem
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Use case

Currently, tree shaking completely breaks when using rfw's createCoreWidgets() function, which makes sense, because it includes dynamic IconData.

This is pretty bad when you're using a big icon library in your app, for example the highly popular [material_symbols_icons](https://pub.dev/packages/material_symbols_icons).
In our case, this would bloat the apk bundle size by 15.6 mb all by itself.

Switching to individual svg icons in a storage bucket somewhere is the much more sensible choice here in our case.

This seems to only be caused by `_coreWidgetsDefinitions` being an all or nothing approach instead of being modular.

Our quickfix was to copy the entire core_widgets.dart file into our repository and comment out the Icon widget. This worked, but now we need to keep this file up to date with upstream :(

## Related

- https://github.com/flutter/flutter/issues/162152
- https://github.com/flutter/flutter/issues/143677
(both closed due to inactivity)

I strongly believe that Icon shouldn't be in the list of core widgets by default, since it can unexpectedly bloat the app by a lot.

### Proposal

- Export each widget as a lowercase function, ie `animationDefaults(context, source)`.
Not sure what the benefit of `Map get _coreWidgetsDefinitions` is over such a list. Maybe slightly less code? Maybe it can be autogenerated slightly easier? I have no idea to be honest, but the downside is clear to me.
- `createSomeCoreWidgets` gets a list of these functions and it only constructs them
- There should be a `defaultCoreWidgets` list that doesn't contain the `Icon` widget

**Non breaking version:**
- `createCoreWidgets` by default still exports all

**Breaking version:**
- `createCoreWidgets` by default doesn't export the icon, but you can manually add it by passing icon() separately.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.