Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:firebase_auth/firebase_auth.dart' as fba;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:firebase_ui_oauth/firebase_ui_oauth.dart';

Expand Down Expand Up @@ -392,7 +391,12 @@ class _ButtonContent extends StatelessWidget {
Widget build(BuildContext context) {
final icon = Padding(
padding: EdgeInsets.all(iconPadding),
child: SvgPicture.string(iconSrc, width: height, height: height),
child: OAuthProviderIcon(
src: iconSrc,
package: assetsPackage,
width: height,
height: height,
),
);

if (label.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@

import 'package:flutter/material.dart';
import 'package:firebase_ui_shared/firebase_ui_shared.dart';
import 'package:flutter_svg/svg.dart';
import 'package:vector_graphics/vector_graphics.dart';

/// {@template ui.oauth.themed_oauth_provider_button_style}
/// An object that is being used to resolve a style of the button.
/// {@endtemplate}
abstract class ThemedOAuthProviderButtonStyle {
/// 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
/// ```
///
/// The package declaring the assets must list `vector_graphics_compiler`
/// under `dependencies` (not `dev_dependencies`) so that the transformer
/// can be resolved when building the consuming app.
ThemedIconSrc get iconSrc;
ThemedColor get backgroundColor;
ThemedColor get color;
ThemedColor get iconBackgroundColor => backgroundColor;
ThemedColor get borderColor => backgroundColor;
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;


/// A custom label string.
Expand All @@ -27,9 +45,9 @@ abstract class ThemedOAuthProviderButtonStyle {
/// Profile Screen.
ThemedValue<Widget> get iconWidget => ThemedValue(
// Display the light icon on a dark background.
SvgPicture.string(iconSrc.light),
OAuthProviderIcon(src: iconSrc.light, package: assetsPackage),
// Display the dark icon on a light background.
SvgPicture.string(iconSrc.dark),
OAuthProviderIcon(src: iconSrc.dark, package: assetsPackage),
);

/// {@macro ui.oauth.themed_oauth_provider_button_style}
Expand Down Expand Up @@ -67,3 +85,36 @@ class OAuthProviderButtonStyle {
required this.iconBackgroundColor,
});
}

/// {@template ui.oauth.oauth_provider_icon}
/// Renders an SVG icon asset compiled by the `vector_graphics_compiler`
/// asset transformer.
/// {@endtemplate}
class OAuthProviderIcon extends StatelessWidget {
/// The asset path of the precompiled icon.
final String src;

/// The package that contains the [src] asset.
final String? package;

final double? width;
final double? height;

/// {@macro ui.oauth.oauth_provider_icon}
const OAuthProviderIcon({
super.key,
required this.src,
this.package,
this.width,
this.height,
});

@override
Widget build(BuildContext context) {
return VectorGraphic(
loader: AssetBytesLoader(src, packageName: package),
width: width,
height: height,
);
}
}
3 changes: 2 additions & 1 deletion packages/firebase_ui_oauth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ dependencies:
firebase_auth: ^7.0.0
firebase_ui_auth: ^4.0.0
firebase_ui_shared: ^1.5.0
flutter_svg: ^2.0.9
flutter_web_auth_2: ^5.1.0
http: ^1.6.0
vector_graphics: ^1.1.19
flutter:
sdk: flutter

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
vector_graphics_compiler: ^1.1.19

false_secrets:
- "/example/**/google-services.json"
Expand Down
33 changes: 12 additions & 21 deletions packages/firebase_ui_oauth/test/flutterfire_ui_oauth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import 'package:firebase_auth/firebase_auth.dart' as fba;
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:firebase_ui_oauth/firebase_ui_oauth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:vector_graphics/vector_graphics.dart';
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart'
show encodeSvg;

class FakeAssetBundle extends Fake implements AssetBundle {
final String svgStr = '''<svg viewBox="0 0 10 10"></svg>''';

@override
Future<String> loadString(String key, {bool cache = true}) async => svgStr;
Future<ByteData> load(String key) async {
final bytes = encodeSvg(xml: svgStr, debugName: key);
return bytes.buffer.asByteData();
}
}

// Duplicated from packages/firebase_ui_oauth_google/lib/src/theme.dart
Expand All @@ -26,24 +32,9 @@ const _backgroundColor = ThemedColor(_googleBlue, _googleWhite);
const _color = ThemedColor(_googleWhite, _googleDark);
const _iconBackgroundColor = ThemedColor(_googleWhite, _googleWhite);

const _iconSvg = '''
<svg width="38px" height="38px" viewBox="0 0 38 38" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Google-Button" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="btn_google_signin_dark_normal" transform="translate(-5.000000, -5.000000)">
<rect id="button-bg-copy" fill="#FFFFFF" x="5" y="5" width="38" height="38" rx="1"></rect>
<g id="logo_googleg_48dp" transform="translate(15.000000, 15.000000)">
<path d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z" id="Shape" fill="#4285F4"></path>
<path d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z" id="Shape" fill="#34A853"></path>
<path d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z" id="Shape" fill="#FBBC05"></path>
<path d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z" id="Shape" fill="#EA4335"></path>
<polygon id="Shape" points="0 0 18 0 18 18 0 18"></polygon>
</g>
</g>
</g>
</svg>
''';

const _iconSrc = ThemedIconSrc(_iconSvg, _iconSvg);
const _iconAsset = 'assets/icons/google.svg';

const _iconSrc = ThemedIconSrc(_iconAsset, _iconAsset);

class GoogleProviderButtonStyle extends ThemedOAuthProviderButtonStyle {
const GoogleProviderButtonStyle();
Expand Down Expand Up @@ -193,7 +184,7 @@ void main() {
await tester.pumpWidget(renderMaterialButton());

final iconFinder = find.byWidgetPredicate(
(widget) => widget is SvgPicture,
(widget) => widget is VectorGraphic,
);

expect(iconFinder, findsOneWidget);
Expand Down
8 changes: 8 additions & 0 deletions packages/firebase_ui_oauth_apple/assets/icons/apple_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions packages/firebase_ui_oauth_apple/assets/icons/apple_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 4 additions & 23 deletions packages/firebase_ui_oauth_apple/lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,10 @@ const _appleWhite = Color(0xffffffff);
const _backgroundColor = ThemedColor(_appleWhite, _appleBlack);
const _color = ThemedColor(_appleBlack, _appleWhite);

const _iconSvgLight = '''
<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">
<rect id="Rectangle" fill="#FFFFFF" x="0" y="0" width="44" height="44"></rect>
<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>
</g>
</g>
</svg>
''';

const _iconSvgDark = '''
<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">
<rect id="Rectangle" fill="#000000" x="0" y="0" width="44" height="44"></rect>
<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>
</g>
</g>
</svg>
''';

const _iconSrc = ThemedIconSrc(_iconSvgLight, _iconSvgDark);
const _iconSrc = ThemedIconSrc(
'assets/icons/apple_light.svg',
'assets/icons/apple_dark.svg',
);

class AppleProviderButtonStyle extends ThemedOAuthProviderButtonStyle {
const AppleProviderButtonStyle();
Expand Down
41 changes: 10 additions & 31 deletions packages/firebase_ui_oauth_apple/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ environment:
dependencies:
firebase_auth: ^7.0.0
firebase_ui_oauth: ^3.0.0
vector_graphics_compiler: ^1.1.19
flutter:
sdk: flutter

Expand All @@ -29,34 +30,12 @@ false_secrets:

# The following section is specific to Flutter packages.
flutter:

# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware

# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
# SVG icons are compiled to the vector_graphics binary format at build
# time, so the output always matches the app's resolved codec version.
assets:
- path: assets/icons/apple_light.svg
transformers:
- package: vector_graphics_compiler
- path: assets/icons/apple_dark.svg
transformers:
- package: vector_graphics_compiler
7 changes: 7 additions & 0 deletions packages/firebase_ui_oauth_facebook/assets/icons/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 2 additions & 10 deletions packages/firebase_ui_oauth_facebook/lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ const _facebookWhite = Color(0xffffffff);
const _backgroundColor = ThemedColor(_facebookBlue, _facebookBlue);
const _color = ThemedColor(_facebookWhite, _facebookWhite);

const _iconSvg = '''<?xml version="1.0" encoding="UTF-8"?>
<svg width="1428px" height="1428px" viewBox="0 0 1428 1428" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>f_logo_RGB-White_1024</title>
<g id="f_logo_RGB-White_1024" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path d="M1031.76618,715.821184 C1031.76618,540.23251 889.423667,397.89 713.834994,397.89 C538.24632,397.89 395.90381,540.23251 395.90381,715.821184 C395.90381,874.509827 512.166649,1006.03895 664.158246,1029.89 L664.158246,807.723166 L583.433532,807.723166 L583.433532,715.821184 L664.158246,715.821184 L664.158246,645.77697 C664.158246,566.095467 711.623137,522.081869 784.245574,522.081869 C819.029853,522.081869 855.413724,528.291462 855.413724,528.291462 L855.413724,606.532339 L815.323347,606.532339 C775.82847,606.532339 763.511741,631.039742 763.511741,656.182385 L763.511741,715.821184 L851.687968,715.821184 L837.592191,807.723166 L763.511741,807.723166 L763.511741,1029.89 C915.503339,1006.03895 1031.76618,874.509827 1031.76618,715.821184" id="Fill-1" fill="#FFFFFE"></path>
</g>
</svg>
''';

const _iconSrc = ThemedIconSrc(_iconSvg, _iconSvg);
const _iconAsset = 'assets/icons/facebook.svg';
const _iconSrc = ThemedIconSrc(_iconAsset, _iconAsset);

class FacebookProviderButtonStyle extends ThemedOAuthProviderButtonStyle {
const FacebookProviderButtonStyle();
Expand Down
Loading
Loading