Commit 0734edbe authored by Adam Barth's avatar Adam Barth Committed by GitHub

Dialogs shouldn't scroll their headers or buttons (#6082)

Rather than scrolling the entire contents of the dialog, we should instead
scroll only the part between the title and the button bar.

Also, polish up the padding in the simple dialog demo.

Fixes #6057
parent 4c5084cb
...@@ -33,16 +33,12 @@ class DialogDemoItem extends StatelessWidget { ...@@ -33,16 +33,12 @@ class DialogDemoItem extends StatelessWidget {
return new InkWell( return new InkWell(
onTap: onPressed, onTap: onPressed,
child: new Padding( child: new Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 24.0),
child: new Row( child: new Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
new Icon( new Icon(icon, size: 36.0, color: color),
icon,
size: 36.0,
color: color
),
new Padding( new Padding(
padding: const EdgeInsets.only(left: 16.0), padding: const EdgeInsets.only(left: 16.0),
child: new Text(text) child: new Text(text)
...@@ -156,6 +152,7 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -156,6 +152,7 @@ class DialogDemoState extends State<DialogDemo> {
context: context, context: context,
dialog: new Dialog( dialog: new Dialog(
title: new Text('Set backup account'), title: new Text('Set backup account'),
contentPadding: const EdgeInsets.only(top: 12.0, bottom: 16.0),
content: new Column( content: new Column(
children: <Widget>[ children: <Widget>[
new DialogDemoItem( new DialogDemoItem(
......
...@@ -81,14 +81,11 @@ class Dialog extends StatelessWidget { ...@@ -81,14 +81,11 @@ class Dialog extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
List<Widget> dialogBody = new List<Widget>(); final List<Widget> children = new List<Widget>();
if (title != null) { if (title != null) {
EdgeInsets padding = titlePadding; children.add(new Padding(
if (padding == null) padding: titlePadding ?? new EdgeInsets.fromLTRB(24.0, 24.0, 24.0, content == null ? 20.0 : 0.0),
padding = new EdgeInsets.fromLTRB(24.0, 24.0, 24.0, content == null ? 20.0 : 0.0);
dialogBody.add(new Padding(
padding: padding,
child: new DefaultTextStyle( child: new DefaultTextStyle(
style: Theme.of(context).textTheme.title, style: Theme.of(context).textTheme.title,
child: title child: title
...@@ -97,20 +94,22 @@ class Dialog extends StatelessWidget { ...@@ -97,20 +94,22 @@ class Dialog extends StatelessWidget {
} }
if (content != null) { if (content != null) {
EdgeInsets padding = contentPadding; children.add(new Flexible(
if (padding == null) fit: FlexFit.loose,
padding = const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0); child: new ScrollableViewport(
dialogBody.add(new Padding( child: new Padding(
padding: padding, padding: contentPadding ?? const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
child: new DefaultTextStyle( child: new DefaultTextStyle(
style: Theme.of(context).textTheme.subhead, style: Theme.of(context).textTheme.subhead,
child: content child: content
)
)
) )
)); ));
} }
if (actions != null) { if (actions != null) {
dialogBody.add(new ButtonTheme.bar( children.add(new ButtonTheme.bar(
child: new ButtonBar( child: new ButtonBar(
alignment: MainAxisAlignment.end, alignment: MainAxisAlignment.end,
children: actions children: actions
...@@ -128,7 +127,11 @@ class Dialog extends StatelessWidget { ...@@ -128,7 +127,11 @@ class Dialog extends StatelessWidget {
color: _getColor(context), color: _getColor(context),
type: MaterialType.card, type: MaterialType.card,
child: new IntrinsicWidth( child: new IntrinsicWidth(
child: new Block(children: dialogBody) child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children
)
) )
) )
) )
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Dialog is scrollable', (WidgetTester tester) async {
bool didPressOk = false;
await tester.pumpWidget(
new MaterialApp(
home: new Material(
child: new Builder(
builder: (BuildContext context) {
return new Center(
child: new RaisedButton(
child: new Text('X'),
onPressed: () {
showDialog(
context: context,
child: new Dialog(
content: new Container(
height: 5000.0,
width: 300.0,
decoration: new BoxDecoration(
backgroundColor: Colors.green[500]
)
),
actions: <Widget>[
new FlatButton(
onPressed: () {
didPressOk = true;
},
child: new Text('OK')
)
]
)
);
}
)
);
}
)
)
)
);
await tester.tap(find.text('X'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1));
expect(didPressOk, false);
await tester.tap(find.text('OK'));
expect(didPressOk, true);
});
}
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