Update ExpansionTile, added a sample app (#10019)

This commit is contained in:
Hans Muller
2017-05-12 09:11:00 -07:00
committed by GitHub
parent ff0aa51326
commit 09e8c2ffb0
3 changed files with 189 additions and 3 deletions

View File

@@ -20,7 +20,9 @@ const Duration _kExpand = const Duration(milliseconds: 200);
/// the tile to reveal or hide the [children].
///
/// This widget is typically used with [ListView] to create an
/// "expand / collapse" list entry.
/// "expand / collapse" list entry. When used with scrolling widgets like
/// [ListView], a unique [key] must be specified to enable the [ExpansionTile] to
/// save and restore its expanded state when it is scrolled in and out of view.
///
/// See also:
///
@@ -110,7 +112,11 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
if (_isExpanded)
_controller.forward();
else
_controller.reverse();
_controller.reverse().then((Null value) {
setState(() {
// Rebuild without widget.children.
});
});
PageStorage.of(context)?.writeState(context, _isExpanded);
});
if (widget.onExpansionChanged != null)
@@ -172,10 +178,12 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
..begin = Colors.transparent
..end = widget.backgroundColor ?? Colors.transparent;
final bool closed = !_isExpanded && _controller.isDismissed;
return new AnimatedBuilder(
animation: _controller.view,
builder: _buildChildren,
child: new Column(children: widget.children),
child: closed ? null : new Column(children: widget.children),
);
}
}