Commit 0739dcea authored by Collin Jackson's avatar Collin Jackson Committed by GitHub

Fix #9003 Make DrawerHeader margin configurable (#9006)

parent 606f5622
...@@ -31,6 +31,7 @@ class DrawerHeader extends StatelessWidget { ...@@ -31,6 +31,7 @@ class DrawerHeader extends StatelessWidget {
const DrawerHeader({ const DrawerHeader({
Key key, Key key,
this.decoration, this.decoration,
this.margin: const EdgeInsets.only(bottom: 8.0),
this.padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0), this.padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0),
this.duration: const Duration(milliseconds: 250), this.duration: const Duration(milliseconds: 250),
this.curve: Curves.fastOutSlowIn, this.curve: Curves.fastOutSlowIn,
...@@ -53,6 +54,9 @@ class DrawerHeader extends StatelessWidget { ...@@ -53,6 +54,9 @@ class DrawerHeader extends StatelessWidget {
/// If the child is null, the padding has no effect. /// If the child is null, the padding has no effect.
final EdgeInsets padding; final EdgeInsets padding;
/// The margin around the drawer header.
final EdgeInsets margin;
/// The duration for animations of the [decoration]. /// The duration for animations of the [decoration].
final Duration duration; final Duration duration;
...@@ -72,7 +76,7 @@ class DrawerHeader extends StatelessWidget { ...@@ -72,7 +76,7 @@ class DrawerHeader extends StatelessWidget {
final double statusBarHeight = MediaQuery.of(context).padding.top; final double statusBarHeight = MediaQuery.of(context).padding.top;
return new Container( return new Container(
height: statusBarHeight + _kDrawerHeaderHeight, height: statusBarHeight + _kDrawerHeaderHeight,
margin: const EdgeInsets.only(bottom: 8.0), margin: margin,
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border( border: new Border(
bottom: new BorderSide( bottom: new BorderSide(
......
...@@ -135,6 +135,7 @@ class UserAccountsDrawerHeader extends StatefulWidget { ...@@ -135,6 +135,7 @@ class UserAccountsDrawerHeader extends StatefulWidget {
UserAccountsDrawerHeader({ UserAccountsDrawerHeader({
Key key, Key key,
this.decoration, this.decoration,
this.margin: const EdgeInsets.only(bottom: 8.0),
this.currentAccountPicture, this.currentAccountPicture,
this.otherAccountsPictures, this.otherAccountsPictures,
@required this.accountName, @required this.accountName,
...@@ -146,6 +147,9 @@ class UserAccountsDrawerHeader extends StatefulWidget { ...@@ -146,6 +147,9 @@ class UserAccountsDrawerHeader extends StatefulWidget {
/// with its background color set to the current theme's primaryColor is used. /// with its background color set to the current theme's primaryColor is used.
final Decoration decoration; final Decoration decoration;
/// The margin around the drawer header.
final EdgeInsets margin;
/// A widget placed in the upper-left corner that represents the current /// A widget placed in the upper-left corner that represents the current
/// user's account. Normally a [CircleAvatar]. /// user's account. Normally a [CircleAvatar].
final Widget currentAccountPicture; final Widget currentAccountPicture;
...@@ -181,6 +185,7 @@ class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> { ...@@ -181,6 +185,7 @@ class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> {
decoration: config.decoration ?? new BoxDecoration( decoration: config.decoration ?? new BoxDecoration(
backgroundColor: Theme.of(context).primaryColor, backgroundColor: Theme.of(context).primaryColor,
), ),
margin: config.margin,
child: new Column( child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
......
...@@ -14,31 +14,33 @@ void main() { ...@@ -14,31 +14,33 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
new Material( new Material(
child: new UserAccountsDrawerHeader( child: new Center(
currentAccountPicture: new CircleAvatar( child: new UserAccountsDrawerHeader(
key: avatarA, currentAccountPicture: new CircleAvatar(
child: new Text('A') key: avatarA,
), child: new Text('A'),
otherAccountsPictures: <Widget>[
new CircleAvatar(
child: new Text('B')
),
new CircleAvatar(
key: avatarC,
child: new Text('C')
), ),
new CircleAvatar( otherAccountsPictures: <Widget>[
key: avatarD, new CircleAvatar(
child: new Text('D') child: new Text('B'),
), ),
new CircleAvatar( new CircleAvatar(
child: new Text('E') key: avatarC,
) child: new Text('C'),
], ),
accountName: new Text("name"), new CircleAvatar(
accountEmail: new Text("email") 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); expect(find.text('A'), findsOneWidget);
...@@ -58,6 +60,9 @@ void main() { ...@@ -58,6 +60,9 @@ void main() {
expect(box.size.width, equals(40.0)); expect(box.size.width, equals(40.0));
expect(box.size.height, 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 topLeft = tester.getTopLeft(find.byType(UserAccountsDrawerHeader));
final Point topRight = tester.getTopRight(find.byType(UserAccountsDrawerHeader)); final Point topRight = tester.getTopRight(find.byType(UserAccountsDrawerHeader));
...@@ -80,19 +85,25 @@ void main() { ...@@ -80,19 +85,25 @@ void main() {
Widget accountName, Widget accountName,
Widget accountEmail, Widget accountEmail,
VoidCallback onDetailsPressed, VoidCallback onDetailsPressed,
EdgeInsets margin,
}) { }) {
return new Material( return new Material(
child: new UserAccountsDrawerHeader( child: new Center(
currentAccountPicture: currentAccountPicture, child: new UserAccountsDrawerHeader(
otherAccountsPictures: otherAccountsPictures, currentAccountPicture: currentAccountPicture,
accountName: accountName, otherAccountsPictures: otherAccountsPictures,
accountEmail: accountEmail, accountName: accountName,
onDetailsPressed: onDetailsPressed, accountEmail: accountEmail,
onDetailsPressed: onDetailsPressed,
margin: margin,
),
), ),
); );
} }
await tester.pumpWidget(buildFrame()); 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); expect(find.byType(Icon), findsNothing);
await tester.pumpWidget(buildFrame( await tester.pumpWidget(buildFrame(
......
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