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