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

@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.

aebrahim pushed a commit to aebrahim/FirebaseUI-Flutter that referenced this pull request Nov 18, 2026
## Description

The `firebase_ui_oauth` example app never calls `Firebase.initializeApp()`.
`OAuthProviderButtonBase` resolves `FirebaseAuth.instance` in `initState`, so
every button throws on startup ("Null check operator used on a null value"
from `Firebase.app()` on web) and the example renders error widgets instead
of the provider buttons.

This initializes Firebase with the example's existing
`firebase_options.dart`, matching the other example apps in the repo
(`firebase_ui_auth`, `firebase_ui_firestore`, `firebase_ui_database`,
`firebase_ui_storage`, `firebase_ui_localizations`).

### Verification

- `dart analyze --fatal-infos` reports no issues in the example.
- `flutter build web` succeeds. In a headless browser the app now renders
  the Apple, Facebook, Google and Twitter buttons with their icons, with no
  console errors. Before this change the button area was an error widget.
- `melos run analyze` and `melos run test:unit:all` pass.

## Related Issues

Found while testing firebase#752.

## 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.
- [x] All existing and new tests are passing.
- [ ] 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

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N9vW6UAypN8gghMxWzymfC
aebrahim added a commit to aebrahim/FirebaseUI-Flutter that referenced this pull request Nov 18, 2026
The `firebase_ui_oauth` example app never calls `Firebase.initializeApp()`.
`OAuthProviderButtonBase` resolves `FirebaseAuth.instance` in `initState`, so
every button throws on startup ("Null check operator used on a null value"
from `Firebase.app()` on web) and the example renders error widgets instead
of the provider buttons.

This initializes Firebase with the example's existing
`firebase_options.dart`, matching the other example apps in the repo
(`firebase_ui_auth`, `firebase_ui_firestore`, `firebase_ui_database`,
`firebase_ui_storage`, `firebase_ui_localizations`).

- `dart analyze --fatal-infos` reports no issues in the example.
- `flutter build web` succeeds. In a headless browser the app now renders
  the Apple, Facebook, Google and Twitter buttons with their icons, with no
  console errors. Before this change the button area was an error widget.
- `melos run analyze` and `melos run test:unit:all` pass.

Found while testing firebase#752.

- [x] 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).
- [x] I read and followed the Flutter Style Guide.
- [x] I signed the CLA.
- [x] I am willing to follow-up on review comments in a timely manner.

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.
@aebrahim
aebrahim force-pushed the feat/oauth-precompiled-svg-icons branch from 79a5ce7 to 89c0463 Compare November 18, 2026 08:12
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.

- **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.
  - Make `assetsPackage` nullable (`String?`). Returning `null` loads icons
    from the app's own bundle, so custom provider styles defined in an app
    (rather than in a package) keep working. Subclasses returning `String`
    still compile.
  - 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`. New tests check that `iconWidget` loads icons from
  `packages/<assetsPackage>/...`, and from the app bundle when
  `assetsPackage` is `null`.

- `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.

Fixes firebase#247

- [ ] 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.

- [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, and `assetsPackage` is now
`String?`. Custom OAuth provider styles must move their SVGs to assets and
declare them with the transformer. A package declaring the assets must list
`vector_graphics_compiler` under `dependencies`; an app declaring them can
use `dev_dependencies` and return `null` from `assetsPackage`.
@aebrahim
aebrahim force-pushed the feat/oauth-precompiled-svg-icons branch from 89c0463 to 3fadf1f Compare November 18, 2026 08:13
aebrahim added a commit to aebrahim/FirebaseUI-Flutter that referenced this pull request Nov 18, 2026
The Apple icon SVGs draw a full-size background rectangle behind the logo:
pure black (`#000000`) in `apple_dark.svg` and pure white (`#FFFFFF`) in
`apple_light.svg`. The Apple button itself is `#060708` on the dark variant,
so a visibly different black square shows behind the logo. The icon also
ignores `iconBackgroundColor`, because the rectangle always covers it.

This removes the rectangles so the logo is drawn on a transparent
background and blends with the button. The logo paths are unchanged. On
the white variant there is no visible difference, since the rectangle was
white on white.

- Rendered the Apple button in the `firebase_ui_oauth` example app on web
  before and after. The square behind the logo on the black button is gone.
- `melos run analyze` and `melos run test:unit:all` pass.

Depends on firebase#752, which
moves the Apple icons into `assets/icons/*.svg`. This PR is based on that
branch; only the last commit is new. Please merge firebase#752 first.

- [x] 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).
- [x] I read and followed the Flutter Style Guide.
- [x] I signed the CLA.
- [s] I am willing to follow-up on review comments in a timely manner.

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.
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

1 participant