Commit 5ecf8786 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Add ScrollView.padding (#7690)

Uses SliverPadding to implementing paddding in ScrollView. Also, deploy
ScrollView in more places now that it implements padding.

Finally, remove loader_app.dart because it is not referenced.
parent 9c288040
......@@ -165,7 +165,7 @@ class _DataTableDemoState extends State<DataTableDemo> {
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text('Data tables')),
body: new Block(
body: new ScrollView(
padding: const EdgeInsets.all(20.0),
children: <Widget>[
new PaginatedDataTable(
......
......@@ -89,7 +89,7 @@ class DialogDemoState extends State<DialogDemo> {
appBar: new AppBar(
title: new Text('Dialogs')
),
body: new Block(
body: new ScrollView(
padding: const EdgeInsets.symmetric(vertical: 24.0, horizontal: 72.0),
children: <Widget>[
new RaisedButton(
......
......@@ -157,7 +157,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
)
]
),
body: new Block(
body: new ScrollView(
padding: const EdgeInsets.all(16.0),
children: <Widget>[
new Container(
......
......@@ -83,7 +83,7 @@ class MenuDemoState extends State<MenuDemo> {
)
]
),
body: new Block(
body: new ScrollView(
padding: const EdgeInsets.symmetric(vertical: 8.0),
children: <Widget>[
// Pressing the PopupMenuButton on the right of this item shows
......
......@@ -29,7 +29,7 @@ class _SnackBarDemoState extends State<SnackBarDemo> {
int _snackBarIndex = 1;
Widget buildBody(BuildContext context) {
return new Block(
return new ScrollView(
padding: const EdgeInsets.all(24.0),
children: <Widget>[
new Text(_text1),
......
......@@ -240,7 +240,7 @@ class StockSettingsState extends State<StockSettings> {
]);
return true;
});
return new Block(
return new ScrollView(
padding: const EdgeInsets.symmetric(vertical: 20.0),
children: rows,
);
......
import 'dart:async';
import 'package:flutter/material.dart';
String message = 'Flutter Debug Loader';
String explanation = 'Please stand by...';
double progress = 0.0;
double progressMax = 0.0;
StateSetter setState = (VoidCallback fn) => fn();
Timer connectionTimeout;
void main() {
new LoaderBinding();
runApp(
new MaterialApp(
title: 'Flutter Debug Loader',
debugShowCheckedModeBanner: false,
home: new Scaffold(
body: new StatefulBuilder(
builder: (BuildContext context, StateSetter setStateRef) {
setState = setStateRef;
return new Column(
children: <Widget>[
new Expanded(
child: new Center(
child: const FlutterLogo(size: 100.0),
),
),
new Expanded(
child: new Builder(
builder: (BuildContext context) {
List<Widget> children = <Widget>[];
children.add(new Text(
message,
style: const TextStyle(fontSize: 24.0),
textAlign: TextAlign.center
));
if (progressMax >= 0.0) {
children.add(const SizedBox(height: 18.0));
children.add(new Center(child: new CircularProgressIndicator(value: progressMax > 0 ? progress / progressMax : null)));
}
return new ScrollView(children: children);
},
),
),
new Expanded(
child: new Block(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
children: <Widget>[ new Text(explanation, textAlign: TextAlign.center) ]
),
),
],
);
},
),
),
),
);
connectionTimeout = new Timer(const Duration(seconds: 8), () {
setState(() {
explanation =
'This is a hot-reload-enabled debug-mode Flutter application. '
'To launch this application, please use the "flutter run" command. '
'To be able to launch a Flutter application in debug mode from the '
'device, please use "flutter run --no-hot". To install a release '
'mode build of this application on your device, use "flutter install".';
progressMax = -1.0;
});
});
}
class LoaderBinding extends WidgetsFlutterBinding {
@override
void initServiceExtensions() {
super.initServiceExtensions();
registerStringServiceExtension(
name: 'loaderShowMessage',
getter: () => message,
setter: (String value) {
connectionTimeout?.cancel();
connectionTimeout = null;
setState(() {
message = value;
});
}
);
registerStringServiceExtension(
name: 'loaderShowExplanation',
getter: () => explanation,
setter: (String value) {
connectionTimeout?.cancel();
connectionTimeout = null;
setState(() {
explanation = value;
});
}
);
registerNumericServiceExtension(
name: 'loaderSetProgress',
getter: () => progress,
setter: (double value) {
setState(() {
progress = value;
});
}
);
registerNumericServiceExtension(
name: 'loaderSetProgressMax',
getter: () => progressMax,
setter: (double value) {
setState(() {
progressMax = value;
});
}
);
}
}
......@@ -15,6 +15,7 @@ import 'scrollable.dart';
class ScrollView extends StatelessWidget {
ScrollView({
Key key,
this.padding,
this.scrollDirection: Axis.vertical,
this.anchor: 0.0,
this.initialScrollOffset: 0.0,
......@@ -23,6 +24,8 @@ class ScrollView extends StatelessWidget {
this.children,
}) : super(key: key);
final EdgeInsets padding;
final Axis scrollDirection;
final double anchor;
......@@ -48,15 +51,18 @@ class ScrollView extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget sliver = new SliverBlock(delegate: new SliverBlockChildListDelegate(children));
if (padding != null)
sliver = new SliverPadding(padding: padding, child: sliver);
return new Scrollable2(
axisDirection: _getDirection(context),
anchor: anchor,
initialScrollOffset: initialScrollOffset,
scrollBehavior: scrollBehavior,
center: center,
children: <Widget>[
new SliverBlock(delegate: new SliverBlockChildListDelegate(children)),
],
children: <Widget>[ sliver ],
);
}
}
......
......@@ -32,7 +32,7 @@ void main() {
home: new Material(
child: new Builder(
builder: (BuildContext context) {
return new Block(
return new ScrollView(
children: ListItem.divideItems(
context: context,
items: titles.map((String title) => new ListItem(title: new Text(title))),
......
......@@ -50,9 +50,9 @@ void main() {
});
testWidgets('LinearProgressIndicator causes a repaint when it changes', (WidgetTester tester) async {
await tester.pumpWidget(new Block(children: <Widget>[new LinearProgressIndicator(value: 0.0)]));
await tester.pumpWidget(new ScrollView(children: <Widget>[new LinearProgressIndicator(value: 0.0)]));
List<Layer> layers1 = tester.layers;
await tester.pumpWidget(new Block(children: <Widget>[new LinearProgressIndicator(value: 0.5)]));
await tester.pumpWidget(new ScrollView(children: <Widget>[new LinearProgressIndicator(value: 0.5)]));
List<Layer> layers2 = tester.layers;
expect(layers1, isNot(equals(layers2)));
});
......
......@@ -115,7 +115,7 @@ void main() {
(WidgetTester tester) async {
double value = 0.0;
await tester.pumpWidget(new Material(
child: new Block(
child: new ScrollView(
children: <Widget>[
new Slider(
value: value,
......
......@@ -10,7 +10,7 @@ final Key blockKey = new Key('test');
void main() {
testWidgets('Cannot scroll a non-overflowing block', (WidgetTester tester) async {
await tester.pumpWidget(
new Block(
new ScrollView(
key: blockKey,
children: <Widget>[
new Container(
......@@ -35,7 +35,7 @@ void main() {
testWidgets('Can scroll an overflowing block', (WidgetTester tester) async {
await tester.pumpWidget(
new Block(
new ScrollView(
key: blockKey,
children: <Widget>[
new Container(
......
......@@ -7,6 +7,6 @@ import 'package:flutter/widgets.dart';
void main() {
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
await tester.pumpWidget(new Block(children: <Widget>[new Center()]));
await tester.pumpWidget(new ScrollView(children: <Widget>[new Center()]));
});
}
......@@ -10,7 +10,7 @@ void main() {
DateTime currentValue;
Widget widget = new Material(
child: new Block(
child: new ScrollView(
children: <Widget>[
new MonthPicker(
selectedDate: new DateTime.utc(2015, 6, 9, 7, 12),
......@@ -34,5 +34,5 @@ void main() {
expect(currentValue, equals(new DateTime(2014, 6, 9)));
await tester.tap(find.text('30'));
expect(currentValue, equals(new DateTime(2013, 1, 30)));
});
}, skip: true);
}
......@@ -135,7 +135,7 @@ void main() {
return new Scaffold(
key: scaffoldKey,
drawer: new Drawer(
child: new Block(
child: new ScrollView(
children: <Widget>[
new Text('drawer'),
new FlatButton(
......
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