From 0739dcea4b4b80ef3dd60dd5159fec2aab2a18c8 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Fri, 24 Mar 2017 16:42:58 -0700 Subject: [PATCH] Fix #9003 Make DrawerHeader margin configurable (#9006) --- .../lib/src/material/drawer_header.dart | 6 +- .../material/user_accounts_drawer_header.dart | 5 ++ .../user_accounts_drawer_header_test.dart | 71 +++++++++++-------- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/packages/flutter/lib/src/material/drawer_header.dart b/packages/flutter/lib/src/material/drawer_header.dart index cc50523352b..ce36fe0c71f 100644 --- a/packages/flutter/lib/src/material/drawer_header.dart +++ b/packages/flutter/lib/src/material/drawer_header.dart @@ -31,6 +31,7 @@ class DrawerHeader extends StatelessWidget { const DrawerHeader({ Key key, this.decoration, + this.margin: const EdgeInsets.only(bottom: 8.0), this.padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0), this.duration: const Duration(milliseconds: 250), this.curve: Curves.fastOutSlowIn, @@ -53,6 +54,9 @@ class DrawerHeader extends StatelessWidget { /// If the child is null, the padding has no effect. final EdgeInsets padding; + /// The margin around the drawer header. + final EdgeInsets margin; + /// The duration for animations of the [decoration]. final Duration duration; @@ -72,7 +76,7 @@ class DrawerHeader extends StatelessWidget { final double statusBarHeight = MediaQuery.of(context).padding.top; return new Container( height: statusBarHeight + _kDrawerHeaderHeight, - margin: const EdgeInsets.only(bottom: 8.0), + margin: margin, decoration: new BoxDecoration( border: new Border( bottom: new BorderSide( 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 08be4a135e3..77c5f718fea 100644 --- a/packages/flutter/lib/src/material/user_accounts_drawer_header.dart +++ b/packages/flutter/lib/src/material/user_accounts_drawer_header.dart @@ -135,6 +135,7 @@ class UserAccountsDrawerHeader extends StatefulWidget { UserAccountsDrawerHeader({ Key key, this.decoration, + this.margin: const EdgeInsets.only(bottom: 8.0), this.currentAccountPicture, this.otherAccountsPictures, @required this.accountName, @@ -146,6 +147,9 @@ class UserAccountsDrawerHeader extends StatefulWidget { /// with its background color set to the current theme's primaryColor is used. final Decoration decoration; + /// The margin around the drawer header. + final EdgeInsets margin; + /// A widget placed in the upper-left corner that represents the current /// user's account. Normally a [CircleAvatar]. final Widget currentAccountPicture; @@ -181,6 +185,7 @@ class _UserAccountsDrawerHeaderState extends State { decoration: config.decoration ?? new BoxDecoration( backgroundColor: Theme.of(context).primaryColor, ), + margin: config.margin, child: new Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ 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 3d11f72898b..83c8faef7b1 100644 --- a/packages/flutter/test/material/user_accounts_drawer_header_test.dart +++ b/packages/flutter/test/material/user_accounts_drawer_header_test.dart @@ -14,31 +14,33 @@ void main() { await tester.pumpWidget( new Material( - child: new UserAccountsDrawerHeader( - currentAccountPicture: new CircleAvatar( - key: avatarA, - child: new Text('A') + child: new Center( + child: new UserAccountsDrawerHeader( + currentAccountPicture: new CircleAvatar( + key: avatarA, + child: new Text('A'), + ), + otherAccountsPictures: [ + new CircleAvatar( + child: new Text('B'), + ), + new CircleAvatar( + key: avatarC, + child: new Text('C'), + ), + new CircleAvatar( + key: avatarD, + child: new Text('D'), + ), + new CircleAvatar( + child: new Text('E'), + ) + ], + accountName: new Text("name"), + accountEmail: new Text("email"), ), - otherAccountsPictures: [ - new CircleAvatar( - child: new Text('B') - ), - new CircleAvatar( - key: avatarC, - child: new Text('C') - ), - new CircleAvatar( - key: avatarD, - child: new Text('D') - ), - new CircleAvatar( - child: new Text('E') - ) - ], - accountName: new Text("name"), - accountEmail: new Text("email") - ) - ) + ), + ), ); expect(find.text('A'), findsOneWidget); @@ -58,6 +60,9 @@ void main() { expect(box.size.width, equals(40.0)); expect(box.size.height, equals(40.0)); + box = tester.renderObject(find.byType(UserAccountsDrawerHeader)); + expect(box.size.height, equals(160.0 + 8.0 + 1.0)); // height + bottom margin + bottom edge) + final Point topLeft = tester.getTopLeft(find.byType(UserAccountsDrawerHeader)); final Point topRight = tester.getTopRight(find.byType(UserAccountsDrawerHeader)); @@ -80,19 +85,25 @@ void main() { Widget accountName, Widget accountEmail, VoidCallback onDetailsPressed, + EdgeInsets margin, }) { return new Material( - child: new UserAccountsDrawerHeader( - currentAccountPicture: currentAccountPicture, - otherAccountsPictures: otherAccountsPictures, - accountName: accountName, - accountEmail: accountEmail, - onDetailsPressed: onDetailsPressed, + child: new Center( + child: new UserAccountsDrawerHeader( + currentAccountPicture: currentAccountPicture, + otherAccountsPictures: otherAccountsPictures, + accountName: accountName, + accountEmail: accountEmail, + onDetailsPressed: onDetailsPressed, + margin: margin, + ), ), ); } await tester.pumpWidget(buildFrame()); + final RenderBox box = tester.renderObject(find.byType(UserAccountsDrawerHeader)); + expect(box.size.height, equals(160.0 + 1.0)); // height + bottom edge) expect(find.byType(Icon), findsNothing); await tester.pumpWidget(buildFrame(