diff --git a/packages/sign_in_with_apple/sign_in_with_apple/lib/src/widgets/sign_in_with_apple_button.dart b/packages/sign_in_with_apple/sign_in_with_apple/lib/src/widgets/sign_in_with_apple_button.dart index 93ff2168..e1cedfbf 100644 --- a/packages/sign_in_with_apple/sign_in_with_apple/lib/src/widgets/sign_in_with_apple_button.dart +++ b/packages/sign_in_with_apple/sign_in_with_apple/lib/src/widgets/sign_in_with_apple_button.dart @@ -13,6 +13,7 @@ class SignInWithAppleButton extends StatelessWidget { super.key, required this.onPressed, this.text = 'Sign in with Apple', + this.textWidget, this.height = 44, this.style = SignInWithAppleButtonStyle.black, this.borderRadius = const BorderRadius.all(Radius.circular(8.0)), @@ -49,6 +50,11 @@ class SignInWithAppleButton extends StatelessWidget { /// This defaults to [IconAlignment.center]. final IconAlignment iconAlignment; + /// The text widget to display next to the Apple logo. + /// + /// If this is set, the [text] parameter will be ignored. + final Widget? textWidget; + /// Returns the background color of the button based on the current [style]. Color get _backgroundColor { switch (style) { @@ -95,19 +101,20 @@ class SignInWithAppleButton extends StatelessWidget { // per Apple's guidelines final fontSize = height * 0.43; - final textWidget = Text( - text, - textAlign: TextAlign.center, - style: TextStyle( - inherit: false, - fontSize: fontSize, - color: _contrastColor, - // defaults styles aligned with https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/cupertino/text_theme.dart#L16 - fontFamily: '.SF Pro Text', - letterSpacing: -0.41, - ), - ); - + // The text widget to display next to the Apple logo + final textWidget = this.textWidget ?? + Text( + text, + textAlign: TextAlign.center, + style: TextStyle( + inherit: false, + fontSize: fontSize, + color: _contrastColor, + // defaults styles aligned with https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/cupertino/text_theme.dart#L16 + fontFamily: '.SF Pro Text', + letterSpacing: -0.41, + ), + ); final appleIcon = Container( width: _appleIconSizeScale * height, height: _appleIconSizeScale * height + 2, diff --git a/packages/sign_in_with_apple/sign_in_with_apple/test/sign_in_with_apple_button/goldens/custom_text_widget.png b/packages/sign_in_with_apple/sign_in_with_apple/test/sign_in_with_apple_button/goldens/custom_text_widget.png new file mode 100644 index 00000000..1e28c057 Binary files /dev/null and b/packages/sign_in_with_apple/sign_in_with_apple/test/sign_in_with_apple_button/goldens/custom_text_widget.png differ diff --git a/packages/sign_in_with_apple/sign_in_with_apple/test/sign_in_with_apple_button/sign_in_with_apple_button_test.dart b/packages/sign_in_with_apple/sign_in_with_apple/test/sign_in_with_apple_button/sign_in_with_apple_button_test.dart index f7bfd063..8f7e00c6 100644 --- a/packages/sign_in_with_apple/sign_in_with_apple/test/sign_in_with_apple_button/sign_in_with_apple_button_test.dart +++ b/packages/sign_in_with_apple/sign_in_with_apple/test/sign_in_with_apple_button/sign_in_with_apple_button_test.dart @@ -191,6 +191,31 @@ Future main() async { skip: !Platform.isMacOS, ); + testWidgets( + 'Allows providing a custom text widget', + (tester) async { + await tester.pumpWidget( + TestSetup( + child: SignInWithAppleButton( + onPressed: () {}, + textWidget: const Text('Apple Login'), + ), + ), + ); + + await expectLater( + find.byType(CupertinoApp), + matchesGoldenFile('goldens/custom_text_widget.png'), + ); + + expect( + find.text('Apple Login'), + findsOneWidget, + ); + }, + skip: !Platform.isMacOS, + ); + testWidgets( 'Calls the onPressed callback when the button is pressed', (tester) async {