33
44import 'dart:math' ;
55
6- import 'package:amplify_auth_cognito/amplify_auth_cognito.dart' ;
76import 'package:amplify_authenticator/src/l10n/auth_strings_resolver.dart' ;
87import 'package:amplify_authenticator/src/state/authenticator_state.dart' ;
98import 'package:amplify_authenticator/src/utils/list.dart' ;
109import 'package:amplify_authenticator/src/widgets/button.dart' ;
1110import 'package:amplify_authenticator/src/widgets/component.dart' ;
1211import 'package:amplify_authenticator/src/widgets/social/social_icons.dart' ;
13- import 'package:aws_common/aws_common .dart' ;
14- import 'package:flutter/foundation.dart' ;
12+ import 'package:amplify_flutter/amplify_flutter .dart' ;
13+ import 'package:flutter/foundation.dart' hide Category ;
1514import 'package:flutter/material.dart' ;
1615
1716class SocialSignInButtons extends StatelessAuthenticatorComponent {
@@ -46,6 +45,10 @@ class SocialSignInButtons extends StatelessAuthenticatorComponent {
4645 ? .resolve ({}) ??
4746 Theme .of (context).textTheme.labelLarge;
4847 final tp = TextPainter (
48+ // TODO(dnys1): replace with textScaleFactor when min flutter version is bumped to 3.16.0
49+ // see: https://docs.flutter.dev/release/breaking-changes/deprecate-textscalefactor#migrating-code-that-consumes-textscalefactor
50+ // ignore: deprecated_member_use
51+ textScaleFactor: MediaQuery .textScaleFactorOf (context),
4952 text: TextSpan (
5053 text: text,
5154 style: style,
@@ -132,7 +135,15 @@ class SocialSignInButton extends AuthenticatorButton<SocialSignInButton> {
132135
133136class _SocialSignInButtonState
134137 extends AuthenticatorButtonState <SocialSignInButton > {
135- static const _spacing = 5.0 ;
138+ /// The spacing between the logo and its text, in pixels.
139+ static const double spacing = 5 ;
140+
141+ /// The size of the (square) logo, in pixels.
142+ static const double logoSize = 40 ;
143+
144+ static final AmplifyLogger logger = AmplifyLogger .category (Category .auth)
145+ .createChild ('Authenticator' )
146+ .createChild ('SocialSignInButton' );
136147
137148 Widget get icon {
138149 final isDark = Theme .of (context).brightness == Brightness .dark;
@@ -164,16 +175,19 @@ class _SocialSignInButtonState
164175 ],
165176 );
166177 }
167- safePrint ('Unsupported provider: ${widget .provider }' );
178+ logger. error ('Unsupported provider: ${widget .provider }' );
168179 return const SizedBox .shrink ();
169180 }
170181
182+ /// Calculates the horizontal padding of the logo, its text, and the
183+ /// spacing given the current layout [constraints] .
171184 double calculatePadding (BoxConstraints constraints) {
172- final logoWidth = constraints.maxHeight + _spacing;
185+ // Split the space remaining after laying out the logo, its text,
186+ // and the spacing.
173187 final textWidth = widget.maxWidth;
174188 return max (
175189 0 ,
176- (constraints.maxWidth - logoWidth - textWidth) / 2 ,
190+ (constraints.maxWidth - logoSize - spacing - textWidth) / 2 ,
177191 );
178192 }
179193
@@ -191,8 +205,8 @@ class _SocialSignInButtonState
191205 @override
192206 Widget build (BuildContext context) {
193207 final resolver = stringResolver.buttons;
194- return SizedBox (
195- height : 40 ,
208+ return ConstrainedBox (
209+ constraints : const BoxConstraints (minHeight : 40 ) ,
196210 child: OutlinedButton (
197211 focusNode: focusNode,
198212 style: ButtonStyle (
@@ -211,18 +225,23 @@ class _SocialSignInButtonState
211225 ? MainAxisAlignment .center
212226 : MainAxisAlignment .start,
213227 children: [
214- Padding (
215- padding : widget.provider.padding ,
216- child: AspectRatio (
217- aspectRatio : 1 ,
228+ SizedBox . square (
229+ dimension : logoSize ,
230+ child: Padding (
231+ padding : widget.provider.logoInsets ,
218232 child: icon,
219233 ),
220234 ),
221- const SizedBox (width: _spacing),
222- Text (
223- resolver.resolve (
224- context,
225- ButtonResolverKey .signInWith (widget.provider),
235+ const SizedBox (width: spacing),
236+ Expanded (
237+ child: Padding (
238+ padding: const EdgeInsets .symmetric (vertical: 4 ),
239+ child: Text (
240+ resolver.resolve (
241+ context,
242+ ButtonResolverKey .signInWith (widget.provider),
243+ ),
244+ ),
226245 ),
227246 ),
228247 ],
@@ -236,10 +255,12 @@ class _SocialSignInButtonState
236255}
237256
238257extension on AuthProvider {
239- EdgeInsets get padding {
240- if (this == AuthProvider .google) {
241- return const EdgeInsets .all (8 );
242- }
243- return EdgeInsets .zero;
244- }
258+ /// The insets of the logo image in its bounding box.
259+ ///
260+ /// Used to provide additional padding for the logos which don't have
261+ /// padding built into their vector image.
262+ EdgeInsets get logoInsets => switch (this ) {
263+ AuthProvider .google => const EdgeInsets .all (8 ),
264+ _ => EdgeInsets .zero,
265+ };
245266}
0 commit comments