Repository navigation
Conversation
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`.
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.
There was a problem hiding this comment.
Code Review
This pull request migrates the SVG rendering in firebase_ui_oauth and its provider packages (Apple, Facebook, Google, and Twitter) from flutter_svg to vector_graphics using precompiled vector graphics. It replaces inline SVG strings with asset paths, introduces the OAuthProviderIcon widget, and updates the build configuration to use the vector_graphics_compiler transformer. Feedback highlights that the newly added Apple SVG icons contain an invalid XML id attribute ("") which should be corrected. Additionally, the transition from inline SVG strings to precompiled asset paths represents a breaking change for custom provider styles, which should be documented.
| <svg width="44px" height="44px" viewBox="0 0 44 44" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
| <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> | ||
| <g id="apple_dark" fill-rule="nonzero"> | ||
| <path d="M22.2226562,14.3846154 C23.0546875,14.3846154 24.0976562,13.8048315 24.71875,13.0317864 C25.28125,12.3312142 25.6914062,11.352829 25.6914062,10.3744437 C25.6914062,10.2415766 25.6796875,10.1087095 25.65625,10 C24.7304687,10.0362365 23.6171875,10.640178 22.9492187,11.4494596 C22.421875,12.06548 21.9414062,13.0317864 21.9414062,14.0222505 C21.9414062,14.1671964 21.9648438,14.3121424 21.9765625,14.3604577 C22.0351562,14.3725366 22.1289062,14.3846154 22.2226562,14.3846154 Z M19.2929688,29 C20.4296875,29 20.9335938,28.214876 22.3515625,28.214876 C23.7929688,28.214876 24.109375,28.9758423 25.375,28.9758423 C26.6171875,28.9758423 27.4492188,27.792117 28.234375,26.6325493 C29.1132812,25.3038779 29.4765625,23.9993643 29.5,23.9389701 C29.4179688,23.9148125 27.0390625,22.9122695 27.0390625,20.0979021 C27.0390625,17.6579784 28.9140625,16.5588048 29.0195312,16.474253 C27.7773438,14.6382708 25.890625,14.5899555 25.375,14.5899555 C23.9804688,14.5899555 22.84375,15.4596313 22.1289062,15.4596313 C21.3554688,15.4596313 20.3359375,14.6382708 19.1289062,14.6382708 C16.8320312,14.6382708 14.5,16.5950413 14.5,20.2911634 C14.5,22.5861411 15.3671875,25.013986 16.4335938,26.5842339 C17.3476562,27.9129053 18.1445312,29 19.2929688,29 Z" id="" fill="#FFFFFF"></path> |
There was a problem hiding this comment.
The id attribute is set to "" (U+F8FF), which is a Private Use Area character. According to the XML 1.0 specification, a valid XML ID must start with a valid NameStartChar, which excludes Private Use Area characters. While some SVG parsers are lenient, strict XML parsers or future toolchains might fail to parse this SVG. Since this ID is not referenced anywhere else in the SVG, it is recommended to either remove the id attribute entirely or change it to a valid ASCII name like apple-logo.
<path d="M22.2226562,14.3846154 C23.0546875,14.3846154 24.0976562,13.8048315 24.71875,13.0317864 C25.28125,12.3312142 25.6914062,11.352829 25.6914062,10.3744437 C25.6914062,10.2415766 25.6796875,10.1087095 25.65625,10 C24.7304687,10.0362365 23.6171875,10.640178 22.9492187,11.4494596 C22.421875,12.06548 21.9414062,13.0317864 21.9414062,14.0222505 C21.9414062,14.1671964 21.9648438,14.3121424 21.9765625,14.3604577 C22.0351562,14.3725366 22.1289062,14.3846154 22.2226562,14.3846154 Z M19.2929688,29 C20.4296875,29 20.9335938,28.214876 22.3515625,28.214876 C23.7929688,28.214876 24.109375,28.9758423 25.375,28.9758423 C26.6171875,28.9758423 27.4492188,27.792117 28.234375,26.6325493 C29.1132812,25.3038779 29.4765625,23.9993643 29.5,23.9389701 C29.4179688,23.9148125 27.0390625,22.9122695 27.0390625,20.0979021 C27.0390625,17.6579784 28.9140625,16.5588048 29.0195312,16.474253 C27.7773438,14.6382708 25.890625,14.5899555 25.375,14.5899555 C23.9804688,14.5899555 22.84375,15.4596313 22.1289062,15.4596313 C21.3554688,15.4596313 20.3359375,14.6382708 19.1289062,14.6382708 C16.8320312,14.6382708 14.5,16.5950413 14.5,20.2911634 C14.5,22.5861411 15.3671875,25.013986 16.4335938,26.5842339 C17.3476562,27.9129053 18.1445312,29 19.2929688,29 Z" id="apple-logo" fill="#FFFFFF"></path>
| <svg width="44px" height="44px" viewBox="0 0 44 44" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
| <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> | ||
| <g id="apple_light" fill-rule="nonzero"> | ||
| <path d="M22.2226562,14.3846154 C23.0546875,14.3846154 24.0976562,13.8048315 24.71875,13.0317864 C25.28125,12.3312142 25.6914062,11.352829 25.6914062,10.3744437 C25.6914062,10.2415766 25.6796875,10.1087095 25.65625,10 C24.7304687,10.0362365 23.6171875,10.640178 22.9492187,11.4494596 C22.421875,12.06548 21.9414062,13.0317864 21.9414062,14.0222505 C21.9414062,14.1671964 21.9648438,14.3121424 21.9765625,14.3604577 C22.0351562,14.3725366 22.1289062,14.3846154 22.2226562,14.3846154 Z M19.2929688,29 C20.4296875,29 20.9335938,28.214876 22.3515625,28.214876 C23.7929688,28.214876 24.109375,28.9758423 25.375,28.9758423 C26.6171875,28.9758423 27.4492188,27.792117 28.234375,26.6325493 C29.1132812,25.3038779 29.4765625,23.9993643 29.5,23.9389701 C29.4179688,23.9148125 27.0390625,22.9122695 27.0390625,20.0979021 C27.0390625,17.6579784 28.9140625,16.5588048 29.0195312,16.474253 C27.7773438,14.6382708 25.890625,14.5899555 25.375,14.5899555 C23.9804688,14.5899555 22.84375,15.4596313 22.1289062,15.4596313 C21.3554688,15.4596313 20.3359375,14.6382708 19.1289062,14.6382708 C16.8320312,14.6382708 14.5,16.5950413 14.5,20.2911634 C14.5,22.5861411 15.3671875,25.013986 16.4335938,26.5842339 C17.3476562,27.9129053 18.1445312,29 19.2929688,29 Z" id="" fill="#000000"></path> |
There was a problem hiding this comment.
The id attribute is set to "" (U+F8FF), which is a Private Use Area character. According to the XML 1.0 specification, a valid XML ID must start with a valid NameStartChar, which excludes Private Use Area characters. While some SVG parsers are lenient, strict XML parsers or future toolchains might fail to parse this SVG. Since this ID is not referenced anywhere else in the SVG, it is recommended to either remove the id attribute entirely or change it to a valid ASCII name like apple-logo.
<path d="M22.2226562,14.3846154 C23.0546875,14.3846154 24.0976562,13.8048315 24.71875,13.0317864 C25.28125,12.3312142 25.6914062,11.352829 25.6914062,10.3744437 C25.6914062,10.2415766 25.6796875,10.1087095 25.65625,10 C24.7304687,10.0362365 23.6171875,10.640178 22.9492187,11.4494596 C22.421875,12.06548 21.9414062,13.0317864 21.9414062,14.0222505 C21.9414062,14.1671964 21.9648438,14.3121424 21.9765625,14.3604577 C22.0351562,14.3725366 22.1289062,14.3846154 22.2226562,14.3846154 Z M19.2929688,29 C20.4296875,29 20.9335938,28.214876 22.3515625,28.214876 C23.7929688,28.214876 24.109375,28.9758423 25.375,28.9758423 C26.6171875,28.9758423 27.4492188,27.792117 28.234375,26.6325493 C29.1132812,25.3038779 29.4765625,23.9993643 29.5,23.9389701 C29.4179688,23.9148125 27.0390625,22.9122695 27.0390625,20.0979021 C27.0390625,17.6579784 28.9140625,16.5588048 29.0195312,16.474253 C27.7773438,14.6382708 25.890625,14.5899555 25.375,14.5899555 C23.9804688,14.5899555 22.84375,15.4596313 22.1289062,15.4596313 C21.3554688,15.4596313 20.3359375,14.6382708 19.1289062,14.6382708 C16.8320312,14.6382708 14.5,16.5950413 14.5,20.2911634 C14.5,22.5861411 15.3671875,25.013986 16.4335938,26.5842339 C17.3476562,27.9129053 18.1445312,29 19.2929688,29 Z" id="apple-logo" fill="#000000"></path>
| /// Asset paths (relative to [assetsPackage]) of the light and dark icons. | ||
| /// | ||
| /// Icons must be compiled into the `vector_graphics` binary format. Declare | ||
| /// the SVG assets with the `vector_graphics_compiler` asset transformer: | ||
| /// | ||
| /// ```yaml | ||
| /// flutter: | ||
| /// assets: | ||
| /// - path: assets/icon.svg | ||
| /// transformers: | ||
| /// - package: vector_graphics_compiler | ||
| /// ``` | ||
| /// | ||
| /// When the assets are declared by a package (see [assetsPackage]), that | ||
| /// package must list `vector_graphics_compiler` under `dependencies` (not | ||
| /// `dev_dependencies`) so that the transformer can be resolved when | ||
| /// building the consuming app. When the assets are declared by the app | ||
| /// itself, a `dev_dependencies` entry in the app is enough. | ||
| ThemedIconSrc get iconSrc; |
There was a problem hiding this comment.
By migrating from flutter_svg to vector_graphics and using AssetBytesLoader, iconSrc must now be an asset path to a precompiled vector graphic. Previously, some implementations or custom provider styles might have used inline SVG strings for iconSrc. This change completely removes support for inline SVG strings.
Since ThemedOAuthProviderButtonStyle is a public class, this is technically a breaking change for any consumer who has implemented a custom provider style using inline SVG strings. Please consider updating the PR description's Breaking Change checklist to Yes and potentially adding a migration note in the changelog/documentation.
The Apple icon SVGs draw a full-size background rectangle behind the logo:
pure black (
#000000) inapple_dark.svgand pure white (#FFFFFF) inapple_light.svg. The Apple button itself is#060708on 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.
firebase_ui_oauthexample app on webbefore and after. The square behind the logo on the black button is gone.
melos run analyzeandmelos run test:unit:allpass.Depends on #752, which
moves the Apple icons into
assets/icons/*.svg. This PR is based on thatbranch; only the last commit is new. Please merge #752 first.
Checklist
///).melos run analyze) does not report any problems on my PR.melos run test:unit:alldoesn't fail).Breaking Change