From fad18d6c1e116ef47a6f0f8e53c74f661f597593 Mon Sep 17 00:00:00 2001 From: burekas7 Date: Wed, 3 Feb 2021 20:56:05 +0200 Subject: [PATCH] [UserAccountsDrawerHeader] New option for changing profiles images size (#73105) --- .../material/user_accounts_drawer_header.dart | 36 ++++++--- .../user_accounts_drawer_header_test.dart | 75 ++++++++++++------- 2 files changed, 73 insertions(+), 38 deletions(-) diff --git a/packages/flutter/lib/src/material/user_accounts_drawer_header.dart b/packages/flutter/lib/src/material/user_accounts_drawer_header.dart index 9bc792a754..7e46041307 100644 --- a/packages/flutter/lib/src/material/user_accounts_drawer_header.dart +++ b/packages/flutter/lib/src/material/user_accounts_drawer_header.dart @@ -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? 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? 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 { child: _AccountPictures( currentAccountPicture: widget.currentAccountPicture, otherAccountsPictures: widget.otherAccountsPictures, + currentAccountPictureSize: widget.currentAccountPictureSize, + otherAccountsPicturesSize: widget.otherAccountsPicturesSize, ), ), ), diff --git a/packages/flutter/test/material/user_accounts_drawer_header_test.dart b/packages/flutter/test/material/user_accounts_drawer_header_test.dart index b66530fda0..9f6c5f07f2 100644 --- a/packages/flutter/test/material/user_accounts_drawer_header_test.dart +++ b/packages/flutter/test/material/user_accounts_drawer_header_test.dart @@ -14,10 +14,12 @@ const Key avatarD = Key('D'); Future 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 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( - flags: [SemanticsFlag.scopesRoute], - children: [ - TestSemantics( - flags: [SemanticsFlag.isFocusable], - label: 'Signed in\nname\nemail', - textDirection: TextDirection.ltr, + flags: [SemanticsFlag.scopesRoute], children: [ TestSemantics( - label: r'B', - textDirection: TextDirection.ltr, - ), - TestSemantics( - label: r'C', - textDirection: TextDirection.ltr, - ), - TestSemantics( - label: r'D', - textDirection: TextDirection.ltr, - ), - TestSemantics( - flags: [SemanticsFlag.isButton], - actions: [SemanticsAction.tap], - label: r'Show accounts', + flags: [SemanticsFlag.isFocusable], + label: 'Signed in\nname\nemail', textDirection: TextDirection.ltr, + children: [ + TestSemantics( + label: r'B', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: r'C', + textDirection: TextDirection.ltr, + ), + TestSemantics( + label: r'D', + textDirection: TextDirection.ltr, + ), + TestSemantics( + flags: [SemanticsFlag.isButton], + actions: [SemanticsAction.tap], + label: r'Show accounts', + textDirection: TextDirection.ltr, + ), + ], ), ], ), ], ), - ], - ), ], ), ],