Repository navigation
Conversation
## Description
The OAuth provider buttons (Google, Apple, Facebook, Twitter) store their
icons as inline SVG strings and render them with `flutter_svg`
(`SvgPicture.string`). That means every app parses SVG at runtime and ships
`flutter_svg` plus the SVG parser it pulls in, even though the icons are known
at build time.
This PR moves the icons to SVG assets that are compiled into the
`vector_graphics` binary format by the `vector_graphics_compiler` asset
transformer when the app is built, and renders them with `VectorGraphic`.
Compiling at app build time (rather than committing precompiled `.vec` files)
keeps the binary output in sync with the `vector_graphics` / codec version
resolved by the consuming app.
### Changes
- **firebase_ui_oauth**
- Replace the `flutter_svg` dependency with `vector_graphics`.
- Add `OAuthProviderIcon`, which loads `iconSrc` from `assetsPackage` via
`AssetBytesLoader`. It is used by the button and by
`ThemedOAuthProviderButtonStyle.iconWidget`. The `assetsPackage` getter,
which was previously unused, now drives icon loading.
- Document how custom styles should declare their icon assets.
- **firebase_ui_oauth_{google,apple,facebook,twitter}**
- Move the inline SVG strings to `assets/icons/*.svg`, declared with the
`vector_graphics_compiler` transformer, and point `iconSrc` at them.
- Add `vector_graphics_compiler` as a regular dependency. Flutter runs the
transformer with `dart run` from the consuming app's directory, so it must
be resolvable from the app; as a `dev_dependency` the app build fails with
"Could not find package `vector_graphics_compiler`". The compiler is not
imported by any Dart code, so it is not compiled into apps.
- Google: the unused `assets/google_icon.svg` is moved to
`assets/icons/google.svg`.
- **Tests**: the `firebase_ui_oauth` widget tests now serve icon bytes
produced by `encodeSvg` and look for `VectorGraphic` instead of
`SvgPicture`.
### Verification
- `melos run analyze` reports no issues in any workspace package.
- `melos run test:unit:all` passes: `flutter test` and
`flutter test --platform=chrome` in all 7 packages with tests.
- A standalone web app (outside the workspace) depending on
`firebase_ui_oauth_google` builds with `flutter build web --release`
without depending on the compiler itself, and the bundled
`google.svg` asset is the compiled binary (828 bytes).
- All four providers' icons render correctly in light and dark themes.
Note: after switching branches, `flutter test` may reuse stale assets from
`build/unit_test_assets`; delete that directory if icons render blank.
## Related Issues
Fixes firebase#247
## Checklist
- [ ] I read the Contributor Guide and followed the process outlined there for submitting PRs.
- [x] My PR includes unit or integration tests for _all_ changed/updated/fixed behaviors.
- [x] All existing and new tests are passing.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] The analyzer (`melos run analyze`) does not report any problems on my PR.
- [x] All unit tests pass (`melos run test:unit:all` doesn't fail).
- [ ] I read and followed the Flutter Style Guide.
- [ ] I signed the CLA.
- [ ] I am willing to follow-up on review comments in a timely manner.
## Breaking Change
- [x] Yes, this is a breaking change.
- [ ] No, this is _not_ a breaking change.
BREAKING CHANGE: `ThemedIconSrc` values returned by
`ThemedOAuthProviderButtonStyle.iconSrc` are now asset paths (relative to
`assetsPackage`) of SVG assets declared with the `vector_graphics_compiler`
asset transformer, instead of raw SVG strings. Custom OAuth provider styles
must move their SVGs to assets, declare them with the transformer, and add
`vector_graphics_compiler` as a dependency of the package that declares them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N9vW6UAypN8gghMxWzymfC
There was a problem hiding this comment.
Code Review
This pull request migrates the OAuth provider buttons from using flutter_svg with inline SVG strings to using vector_graphics with precompiled SVG assets. It introduces a new OAuthProviderIcon widget to load and render these compiled assets. The review feedback suggests making assetsPackage nullable in ThemedOAuthProviderButtonStyle to support custom provider styles defined directly in the main application.
| double get iconPadding => 0; | ||
|
|
||
| /// The name of the package that contains the [iconSrc] assets. | ||
| String get assetsPackage; |
There was a problem hiding this comment.
To support custom OAuth provider styles defined directly within the main application (rather than in a separate package), assetsPackage should be nullable (String?). In Flutter, passing null as the package name to asset loaders (like AssetBytesLoader) indicates that the asset should be loaded from the main application's asset bundle.\n\nMaking this change is backward-compatible for existing subclasses that return String.
| String get assetsPackage; | |
| String? get assetsPackage; |
Description
The OAuth provider buttons (Google, Apple, Facebook, Twitter) store their icons as inline SVG strings and render them with
flutter_svg(SvgPicture.string). That means every app parses SVG at runtime and shipsflutter_svgplus the SVG parser it pulls in, even though the icons are known at build time.This PR moves the icons to SVG assets that are compiled into the
vector_graphicsbinary format by thevector_graphics_compilerasset transformer when the app is built, and renders them withVectorGraphic. Compiling at app build time (rather than committing precompiled.vecfiles) keeps the binary output in sync with thevector_graphics/ codec version resolved by the consuming app.Changes
flutter_svgdependency withvector_graphics.OAuthProviderIcon, which loadsiconSrcfromassetsPackageviaAssetBytesLoader. It is used by the button and byThemedOAuthProviderButtonStyle.iconWidget. TheassetsPackagegetter, which was previously unused, now drives icon loading.assets/icons/*.svg, declared with thevector_graphics_compilertransformer, and pointiconSrcat them.vector_graphics_compileras a regular dependency. Flutter runs the transformer withdart runfrom the consuming app's directory, so it must be resolvable from the app; as adev_dependencythe app build fails with "Could not find packagevector_graphics_compiler". The compiler is not imported by any Dart code, so it is not compiled into apps.assets/google_icon.svgis moved toassets/icons/google.svg.firebase_ui_oauthwidget tests now serve icon bytes produced byencodeSvgand look forVectorGraphicinstead ofSvgPicture.Verification
melos run analyzereports no issues in any workspace package.melos run test:unit:allpasses:flutter testandflutter test --platform=chromein all 7 packages with tests.firebase_ui_oauth_googlebuilds withflutter build web --releasewithout depending on the compiler itself, and the bundledgoogle.svgasset is the compiled binary (828 bytes).Note: after switching branches,
flutter testmay reuse stale assets frombuild/unit_test_assets; delete that directory if icons render blank.Related Issues
Fixes #247
Checklist
///).melos run analyze) does not report any problems on my PR.melos run test:unit:alldoesn't fail).Breaking Change
BREAKING CHANGE:
ThemedIconSrcvalues returned byThemedOAuthProviderButtonStyle.iconSrcare now asset paths (relative toassetsPackage) of SVG assets declared with thevector_graphics_compilerasset transformer, instead of raw SVG strings. Custom OAuth provider styles must move their SVGs to assets, declare them with the transformer, and addvector_graphics_compileras a dependency of the package that declares them.Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com