3
3
4
4
import 'dart:math' ;
5
5
6
- import 'package:amplify_auth_cognito/amplify_auth_cognito.dart' ;
7
6
import 'package:amplify_authenticator/src/l10n/auth_strings_resolver.dart' ;
8
7
import 'package:amplify_authenticator/src/state/authenticator_state.dart' ;
9
8
import 'package:amplify_authenticator/src/utils/list.dart' ;
10
9
import 'package:amplify_authenticator/src/widgets/button.dart' ;
11
10
import 'package:amplify_authenticator/src/widgets/component.dart' ;
12
11
import '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 ;
15
14
import 'package:flutter/material.dart' ;
16
15
17
16
class SocialSignInButtons extends StatelessAuthenticatorComponent {
@@ -46,6 +45,10 @@ class SocialSignInButtons extends StatelessAuthenticatorComponent {
46
45
? .resolve ({}) ??
47
46
Theme .of (context).textTheme.labelLarge;
48
47
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),
49
52
text: TextSpan (
50
53
text: text,
51
54
style: style,
@@ -132,7 +135,15 @@ class SocialSignInButton extends AuthenticatorButton<SocialSignInButton> {
132
135
133
136
class _SocialSignInButtonState
134
137
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' );
136
147
137
148
Widget get icon {
138
149
final isDark = Theme .of (context).brightness == Brightness .dark;
@@ -164,16 +175,19 @@ class _SocialSignInButtonState
164
175
],
165
176
);
166
177
}
167
- safePrint ('Unsupported provider: ${widget .provider }' );
178
+ logger. error ('Unsupported provider: ${widget .provider }' );
168
179
return const SizedBox .shrink ();
169
180
}
170
181
182
+ /// Calculates the horizontal padding of the logo, its text, and the
183
+ /// spacing given the current layout [constraints] .
171
184
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.
173
187
final textWidth = widget.maxWidth;
174
188
return max (
175
189
0 ,
176
- (constraints.maxWidth - logoWidth - textWidth) / 2 ,
190
+ (constraints.maxWidth - logoSize - spacing - textWidth) / 2 ,
177
191
);
178
192
}
179
193
@@ -191,8 +205,8 @@ class _SocialSignInButtonState
191
205
@override
192
206
Widget build (BuildContext context) {
193
207
final resolver = stringResolver.buttons;
194
- return SizedBox (
195
- height : 40 ,
208
+ return ConstrainedBox (
209
+ constraints : const BoxConstraints (minHeight : 40 ) ,
196
210
child: OutlinedButton (
197
211
focusNode: focusNode,
198
212
style: ButtonStyle (
@@ -211,18 +225,23 @@ class _SocialSignInButtonState
211
225
? MainAxisAlignment .center
212
226
: MainAxisAlignment .start,
213
227
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 ,
218
232
child: icon,
219
233
),
220
234
),
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
+ ),
226
245
),
227
246
),
228
247
],
@@ -236,10 +255,12 @@ class _SocialSignInButtonState
236
255
}
237
256
238
257
extension 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
+ };
245
266
}
0 commit comments