Commit 9536c418 authored by Hans Muller's avatar Hans Muller

Scaffold saves and restores scrollable state, etc

parent 6d646860
...@@ -14,11 +14,6 @@ enum DialogDemoAction { ...@@ -14,11 +14,6 @@ enum DialogDemoAction {
agree, agree,
} }
const String _introText =
"Use dialogs sparingly because their sudden appearance forces users to stop their "
"current task and focus on the dialog's content. Alternatives to dialogs include "
"menus or inline expansion, both of which maintain the current context.";
const String _alertWithoutTitleText = "Discard draft?"; const String _alertWithoutTitleText = "Discard draft?";
const String _alertWithTitleText = const String _alertWithTitleText =
...@@ -88,27 +83,11 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -88,27 +83,11 @@ class DialogDemoState extends State<DialogDemo> {
toolBar: new ToolBar( toolBar: new ToolBar(
center: new Text('Dialogs') center: new Text('Dialogs')
), ),
body: new ButtonTheme( body: new Block(
color: ButtonColor.accent, padding: const EdgeDims.symmetric(vertical: 24.0, horizontal: 72.0),
child: new Padding(
padding: const EdgeDims.all(24.0),
child: new ScrollableViewport(
child: new Column(
alignItems: FlexAlignItems.stretch,
children: <Widget>[ children: <Widget>[
new Container( new RaisedButton(
child: new Text( child: new Text('ALERT'),
_introText,
style: dialogTextStyle
),
padding: const EdgeDims.only(top: 8.0, bottom: 24.0),
margin: const EdgeDims.only(bottom:16.0),
decoration: new BoxDecoration(
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
)
),
new FlatButton(
child: new Text('Alert without a title'),
onPressed: () { onPressed: () {
showDemoDialog( showDemoDialog(
context: context, context: context,
...@@ -131,8 +110,8 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -131,8 +110,8 @@ class DialogDemoState extends State<DialogDemo> {
); );
} }
), ),
new FlatButton( new RaisedButton(
child: new Text('Alert with a title'), child: new Text('ALERT WITH TITLE'),
onPressed: () { onPressed: () {
showDemoDialog( showDemoDialog(
context: context, context: context,
...@@ -156,8 +135,8 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -156,8 +135,8 @@ class DialogDemoState extends State<DialogDemo> {
); );
} }
), ),
new FlatButton( new RaisedButton(
child: new Text('Simple Dialog'), child: new Text('SIMPLE'),
onPressed: () { onPressed: () {
showDemoDialog( showDemoDialog(
context: context, context: context,
...@@ -188,8 +167,8 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -188,8 +167,8 @@ class DialogDemoState extends State<DialogDemo> {
); );
} }
), ),
new FlatButton( new RaisedButton(
child: new Text('Confirmation Dialog'), child: new Text('CONFIRMATION'),
onPressed: () { onPressed: () {
showTimePicker( showTimePicker(
context: context, context: context,
...@@ -204,8 +183,8 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -204,8 +183,8 @@ class DialogDemoState extends State<DialogDemo> {
}); });
} }
), ),
new FlatButton( new RaisedButton(
child: new Text('Fullscreen Dialog'), child: new Text('FULLSCREEN'),
onPressed: () { onPressed: () {
Navigator.push(context, new MaterialPageRoute( Navigator.push(context, new MaterialPageRoute(
builder: (BuildContext context) => new FullScreenDialogDemo() builder: (BuildContext context) => new FullScreenDialogDemo()
...@@ -214,9 +193,6 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -214,9 +193,6 @@ class DialogDemoState extends State<DialogDemo> {
) )
] ]
) )
)
)
)
); );
} }
} }
...@@ -5,17 +5,6 @@ ...@@ -5,17 +5,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class PageSelectorDemo extends StatelessComponent { class PageSelectorDemo extends StatelessComponent {
Widget _buildTabView(IconData icon) {
return new Container(
key: new ObjectKey(icon),
padding: const EdgeDims.all(12.0),
child: new Card(
child: new Center(
child: new Icon(icon: icon, size: 48.0)
)
)
);
}
void _handleArrowButtonPress(BuildContext context, int delta) { void _handleArrowButtonPress(BuildContext context, int delta) {
final TabBarSelectionState selection = TabBarSelection.of(context); final TabBarSelectionState selection = TabBarSelection.of(context);
...@@ -35,10 +24,11 @@ class PageSelectorDemo extends StatelessComponent { ...@@ -35,10 +24,11 @@ class PageSelectorDemo extends StatelessComponent {
return new Scaffold( return new Scaffold(
toolBar: new ToolBar(center: new Text('Page Selector')), toolBar: new ToolBar(center: new Text('Page Selector')),
body: new TabBarSelection( body: new TabBarSelection<IconData>(
values: icons, values: icons,
child: new Builder( child: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final Color color = Theme.of(context).accentColor;
return new Column( return new Column(
children: <Widget>[ children: <Widget>[
new Container( new Container(
...@@ -47,12 +37,14 @@ class PageSelectorDemo extends StatelessComponent { ...@@ -47,12 +37,14 @@ class PageSelectorDemo extends StatelessComponent {
children: <Widget>[ children: <Widget>[
new IconButton( new IconButton(
icon: Icons.arrow_back, icon: Icons.arrow_back,
color: color,
onPressed: () { _handleArrowButtonPress(context, -1); }, onPressed: () { _handleArrowButtonPress(context, -1); },
tooltip: 'Back' tooltip: 'Back'
), ),
new TabPageSelector<String>(), new TabPageSelector<IconData>(),
new IconButton( new IconButton(
icon: Icons.arrow_forward, icon: Icons.arrow_forward,
color: color,
onPressed: () { _handleArrowButtonPress(context, 1); }, onPressed: () { _handleArrowButtonPress(context, 1); },
tooltip: 'Forward' tooltip: 'Forward'
) )
...@@ -62,7 +54,18 @@ class PageSelectorDemo extends StatelessComponent { ...@@ -62,7 +54,18 @@ class PageSelectorDemo extends StatelessComponent {
), ),
new Flexible( new Flexible(
child: new TabBarView( child: new TabBarView(
children: icons.map(_buildTabView).toList() children: icons.map((IconData icon) {
return new Container(
key: new ObjectKey(icon),
padding: const EdgeDims.all(12.0),
child: new Card(
child: new Center(
child: new Icon(icon: icon, size: 128.0, color: color)
)
)
);
})
.toList()
) )
) )
] ]
......
...@@ -23,7 +23,8 @@ class TabsDemo extends StatelessComponent { ...@@ -23,7 +23,8 @@ class TabsDemo extends StatelessComponent {
Icons.language: 'LANGUAGE', Icons.language: 'LANGUAGE',
}; };
Widget build(_) { Widget build(BuildContext context) {
final Color iconColor = Theme.of(context).accentColor;
return new TabBarSelection( return new TabBarSelection(
values: icons, values: icons,
child: new Scaffold( child: new Scaffold(
...@@ -43,7 +44,13 @@ class TabsDemo extends StatelessComponent { ...@@ -43,7 +44,13 @@ class TabsDemo extends StatelessComponent {
key: new ObjectKey(icon), key: new ObjectKey(icon),
padding: const EdgeDims.all(12.0), padding: const EdgeDims.all(12.0),
child: new Card( child: new Card(
child: new Center(child: new Icon(icon: icon, size: 48.0)) child: new Center(
child: new Icon(
icon: icon,
color: iconColor,
size: 128.0
)
)
) )
); );
}).toList() }).toList()
......
...@@ -345,6 +345,12 @@ class ScaffoldState extends State<Scaffold> { ...@@ -345,6 +345,12 @@ class ScaffoldState extends State<Scaffold> {
void initState() { void initState() {
super.initState(); super.initState();
_appBarController = new AnimationController(); _appBarController = new AnimationController();
List<double> scrollValues = PageStorage.of(context)?.readState(context);
if (scrollValues != null) {
assert(scrollValues.length == 2);
_scrollOffset = scrollValues[0];
_scrollOffsetDelta = scrollValues[1];
}
} }
void dispose() { void dispose() {
...@@ -353,6 +359,7 @@ class ScaffoldState extends State<Scaffold> { ...@@ -353,6 +359,7 @@ class ScaffoldState extends State<Scaffold> {
_snackBarController = null; _snackBarController = null;
_snackBarTimer?.cancel(); _snackBarTimer?.cancel();
_snackBarTimer = null; _snackBarTimer = null;
PageStorage.of(context)?.writeState(context, <double>[_scrollOffset, _scrollOffsetDelta]);
super.dispose(); super.dispose();
} }
......
...@@ -999,7 +999,7 @@ class TabPageSelector<T> extends StatelessComponent { ...@@ -999,7 +999,7 @@ class TabPageSelector<T> extends StatelessComponent {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final TabBarSelectionState selection = TabBarSelection.of(context); final TabBarSelectionState selection = TabBarSelection.of(context);
final Color color = Theme.of(context).primaryColor; final Color color = Theme.of(context).accentColor;
final ColorTween selectedColor = new ColorTween(begin: Colors.transparent, end: color); final ColorTween selectedColor = new ColorTween(begin: Colors.transparent, end: color);
final ColorTween previousColor = new ColorTween(begin: color, end: Colors.transparent); final ColorTween previousColor = new ColorTween(begin: color, end: Colors.transparent);
Animation<double> animation = new CurvedAnimation(parent: selection.animation, curve: Curves.ease); Animation<double> animation = new CurvedAnimation(parent: selection.animation, curve: Curves.ease);
......
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