Unverified Commit fad18d6c authored by burekas7's avatar burekas7 Committed by GitHub

[UserAccountsDrawerHeader] New option for changing profiles images size (#73105)

parent deb5e40f
......@@ -19,10 +19,14 @@ class _AccountPictures extends StatelessWidget {
Key? key,
this.currentAccountPicture,
this.otherAccountsPictures,
this.currentAccountPictureSize,
this.otherAccountsPicturesSize,
}) : super(key: key);
final Widget? currentAccountPicture;
final List<Widget>? otherAccountsPictures;
final Size? currentAccountPictureSize;
final Size? otherAccountsPicturesSize;
@override
Widget build(BuildContext context) {
......@@ -37,12 +41,13 @@ class _AccountPictures extends StatelessWidget {
padding: const EdgeInsetsDirectional.only(start: 8.0),
child: Semantics(
container: true,
child: Container(
padding: const EdgeInsets.only(left: 8.0, bottom: 8.0),
width: 48.0,
height: 48.0,
child: picture,
),
child: Padding(
padding: const EdgeInsets.only(left: 8.0, bottom: 8.0),
child: SizedBox.fromSize(
size: otherAccountsPicturesSize,
child: picture,
),
),
),
);
}).toList(),
......@@ -52,9 +57,8 @@ class _AccountPictures extends StatelessWidget {
top: 0.0,
child: Semantics(
explicitChildNodes: true,
child: SizedBox(
width: 72.0,
height: 72.0,
child: SizedBox.fromSize(
size: currentAccountPictureSize,
child: currentAccountPicture,
),
),
......@@ -181,8 +185,8 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi
Icons.arrow_drop_down,
color: widget.arrowColor,
semanticLabel: widget.isOpen
? localizations.hideAccountsLabel
: localizations.showAccountsLabel,
? localizations.hideAccountsLabel
: localizations.showAccountsLabel,
),
),
),
......@@ -298,6 +302,8 @@ class UserAccountsDrawerHeader extends StatefulWidget {
this.margin = const EdgeInsets.only(bottom: 8.0),
this.currentAccountPicture,
this.otherAccountsPictures,
this.currentAccountPictureSize = const Size.square(72.0),
this.otherAccountsPicturesSize = const Size.square(40.0),
required this.accountName,
required this.accountEmail,
this.onDetailsPressed,
......@@ -320,6 +326,12 @@ class UserAccountsDrawerHeader extends StatefulWidget {
/// upper-right corner. Normally a list of [CircleAvatar] widgets.
final List<Widget>? otherAccountsPictures;
/// The size of the [currentAccountPicture].
final Size currentAccountPictureSize;
/// The size of each widget in [otherAccountsPicturesSize].
final Size otherAccountsPicturesSize;
/// A widget that represents the user's current account name. It is
/// displayed on the left, below the [currentAccountPicture].
final Widget? accountName;
......@@ -373,6 +385,8 @@ class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> {
child: _AccountPictures(
currentAccountPicture: widget.currentAccountPicture,
otherAccountsPictures: widget.otherAccountsPictures,
currentAccountPictureSize: widget.currentAccountPictureSize,
otherAccountsPicturesSize: widget.otherAccountsPicturesSize,
),
),
),
......
......@@ -14,10 +14,12 @@ const Key avatarD = Key('D');
Future<void> pumpTestWidget(
WidgetTester tester, {
bool withName = true,
bool withEmail = true,
bool withOnDetailsPressedHandler = true,
}) async {
bool withName = true,
bool withEmail = true,
bool withOnDetailsPressedHandler = true,
Size otherAccountsPictureSize = const Size.square(40.0),
Size currentAccountPictureSize = const Size.square(72.0),
}) async {
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
......@@ -33,6 +35,8 @@ Future<void> pumpTestWidget(
child: Center(
child: UserAccountsDrawerHeader(
onDetailsPressed: withOnDetailsPressedHandler ? () { } : null,
currentAccountPictureSize: currentAccountPictureSize,
otherAccountsPicturesSize: otherAccountsPictureSize,
currentAccountPicture: const ExcludeSemantics(
child: CircleAvatar(
key: avatarA,
......@@ -104,6 +108,23 @@ void main() {
expect(avatarDTopRight.dx - avatarCTopRight.dx, equals(40.0 + 16.0)); // size + space between
});
testWidgets('UserAccountsDrawerHeader change default size test', (WidgetTester tester) async {
const Size currentAccountPictureSize = Size.square(60.0);
const Size otherAccountsPictureSize = Size.square(30.0);
await pumpTestWidget(
tester,
currentAccountPictureSize: currentAccountPictureSize,
otherAccountsPictureSize: otherAccountsPictureSize,
);
final RenderBox currentAccountRenderBox = tester.renderObject(find.byKey(avatarA));
final RenderBox otherAccountRenderBox = tester.renderObject(find.byKey(avatarC));
expect(currentAccountRenderBox.size, currentAccountPictureSize);
expect(otherAccountRenderBox.size, otherAccountsPictureSize);
});
testWidgets('UserAccountsDrawerHeader icon rotation test', (WidgetTester tester) async {
await pumpTestWidget(tester);
Transform transformWidget = tester.firstWidget(find.byType(Transform));
......@@ -480,37 +501,37 @@ void main() {
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isFocusable],
label: 'Signed in\nname\nemail',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(
label: r'B',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: r'C',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: r'D',
textDirection: TextDirection.ltr,
),
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isButton],
actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Show accounts',
flags: <SemanticsFlag>[SemanticsFlag.isFocusable],
label: 'Signed in\nname\nemail',
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
label: r'B',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: r'C',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: r'D',
textDirection: TextDirection.ltr,
),
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isButton],
actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Show accounts',
textDirection: TextDirection.ltr,
),
],
),
],
),
],
),
],
),
],
),
],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment