Skip to content

Commit c07cf1b

Browse files
authored
fix(authenticator): Wrap social button text (#3692)
* fix(authenticator): Wrap social button text Prevents overflow of social button text in constrained layouts by wrapping the text. * Update padding * Update TODO
1 parent 0c6ec05 commit c07cf1b

File tree

45 files changed

+49
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+49
-24
lines changed

packages/authenticator/amplify_authenticator/lib/src/widgets/social/social_button.dart

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
import 'dart:math';
55

6-
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
76
import 'package:amplify_authenticator/src/l10n/auth_strings_resolver.dart';
87
import 'package:amplify_authenticator/src/state/authenticator_state.dart';
98
import 'package:amplify_authenticator/src/utils/list.dart';
109
import 'package:amplify_authenticator/src/widgets/button.dart';
1110
import 'package:amplify_authenticator/src/widgets/component.dart';
1211
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;
1514
import 'package:flutter/material.dart';
1615

1716
class 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

133136
class _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

238257
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+
};
245266
}
10.4 KB
13.3 KB
12.6 KB
14.6 KB
17.2 KB
18 KB
11.2 KB
14.2 KB
14.2 KB

0 commit comments

Comments
 (0)