Skip to content

feat(ui_oauth)!: compile provider icons with vector_graphics_compiler - #752

Open
aebrahim wants to merge 1 commit into
firebase:mainfrom
aebrahim:feat/oauth-precompiled-svg-icons
Open

aebrahim wants to merge 1 commit into
firebase:mainfrom
aebrahim:feat/oauth-precompiled-svg-icons

Conversation

@aebrahim

Copy link
Copy Markdown

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 #247

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors.
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • 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

  • 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

## 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

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

Copy link
Copy Markdown

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 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
String get assetsPackage;
String? get assetsPackage;

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.

firebase_ui_oauth: Pre-compile svg icon assets using vector_graphics_compiler

2 participants