Add Container.align and Container.position (#5128)
These let you add Align widget to the inside or outside of a container. Several customers have asked for these properties. Fixes #4950
This commit is contained in:
@@ -406,21 +406,19 @@ class DataTable extends StatelessWidget {
|
||||
label = new Container(
|
||||
padding: padding,
|
||||
height: _kHeadingRowHeight,
|
||||
child: new Align(
|
||||
alignment: new FractionalOffset(numeric ? 1.0 : 0.0, 0.5), // TODO(ianh): RTL for non-numeric
|
||||
child: new AnimatedDefaultTextStyle(
|
||||
style: new TextStyle(
|
||||
// TODO(ianh): font family should be Roboto; see https://github.com/flutter/flutter/issues/3116
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: _kHeadingFontSize,
|
||||
height: _kHeadingRowHeight / _kHeadingFontSize,
|
||||
color: (Theme.of(context).brightness == Brightness.light)
|
||||
? ((onSort != null && sorted) ? Colors.black87 : Colors.black54)
|
||||
: ((onSort != null && sorted) ? Colors.white : Colors.white70)
|
||||
),
|
||||
duration: _kSortArrowAnimationDuration,
|
||||
child: label
|
||||
)
|
||||
align: new FractionalOffset(numeric ? 1.0 : 0.0, 0.5), // TODO(ianh): RTL for non-numeric
|
||||
child: new AnimatedDefaultTextStyle(
|
||||
style: new TextStyle(
|
||||
// TODO(ianh): font family should be Roboto; see https://github.com/flutter/flutter/issues/3116
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: _kHeadingFontSize,
|
||||
height: _kHeadingRowHeight / _kHeadingFontSize,
|
||||
color: (Theme.of(context).brightness == Brightness.light)
|
||||
? ((onSort != null && sorted) ? Colors.black87 : Colors.black54)
|
||||
: ((onSort != null && sorted) ? Colors.white : Colors.white70)
|
||||
),
|
||||
duration: _kSortArrowAnimationDuration,
|
||||
child: label
|
||||
)
|
||||
);
|
||||
if (tooltip != null) {
|
||||
@@ -458,23 +456,21 @@ class DataTable extends StatelessWidget {
|
||||
label = new Container(
|
||||
padding: padding,
|
||||
height: _kDataRowHeight,
|
||||
child: new Align(
|
||||
alignment: new FractionalOffset(numeric ? 1.0 : 0.0, 0.5), // TODO(ianh): RTL for non-numeric
|
||||
child: new DefaultTextStyle(
|
||||
style: new TextStyle(
|
||||
// TODO(ianh): font family should be Roboto; see https://github.com/flutter/flutter/issues/3116
|
||||
fontSize: 13.0,
|
||||
color: isLightTheme
|
||||
? (placeholder ? Colors.black38 : Colors.black87)
|
||||
: (placeholder ? Colors.white30 : Colors.white70)
|
||||
align: new FractionalOffset(numeric ? 1.0 : 0.0, 0.5), // TODO(ianh): RTL for non-numeric
|
||||
child: new DefaultTextStyle(
|
||||
style: new TextStyle(
|
||||
// TODO(ianh): font family should be Roboto; see https://github.com/flutter/flutter/issues/3116
|
||||
fontSize: 13.0,
|
||||
color: isLightTheme
|
||||
? (placeholder ? Colors.black38 : Colors.black87)
|
||||
: (placeholder ? Colors.white30 : Colors.white70)
|
||||
),
|
||||
child: new IconTheme.merge(
|
||||
context: context,
|
||||
data: new IconThemeData(
|
||||
color: isLightTheme ? Colors.black54 : Colors.white70
|
||||
),
|
||||
child: new IconTheme.merge(
|
||||
context: context,
|
||||
data: new IconThemeData(
|
||||
color: isLightTheme ? Colors.black54 : Colors.white70
|
||||
),
|
||||
child: new DropDownButtonHideUnderline(child: label)
|
||||
)
|
||||
child: new DropDownButtonHideUnderline(child: label)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -337,10 +337,8 @@ class DropDownMenuItem<T> extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return new Container(
|
||||
height: _kMenuItemHeight,
|
||||
child: new Align(
|
||||
alignment: FractionalOffset.centerLeft,
|
||||
child: child
|
||||
)
|
||||
align: FractionalOffset.centerLeft,
|
||||
child: child
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,20 +146,18 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
||||
);
|
||||
final bool effectiveCenterTitle = _getEffectiveCenterTitle(theme);
|
||||
final FractionalOffset titleAlignment = effectiveCenterTitle ? FractionalOffset.bottomCenter : FractionalOffset.bottomLeft;
|
||||
children.add(new Padding(
|
||||
children.add(new Container(
|
||||
padding: new EdgeInsets.only(left: effectiveCenterTitle ? 0.0 : 72.0, bottom: 14.0),
|
||||
child: new Align(
|
||||
alignment: new Tween<FractionalOffset>(
|
||||
begin: new FractionalOffset(0.0, yAlignStart),
|
||||
end: new FractionalOffset(0.0, yAlignEnd)
|
||||
).evaluate(scaleAndAlignCurve),
|
||||
child: new ScaleTransition(
|
||||
align: new Tween<FractionalOffset>(
|
||||
begin: new FractionalOffset(0.0, yAlignStart),
|
||||
end: new FractionalOffset(0.0, yAlignEnd)
|
||||
).evaluate(scaleAndAlignCurve),
|
||||
child: new ScaleTransition(
|
||||
alignment: titleAlignment,
|
||||
scale: new Tween<double>(begin: 1.5, end: 1.0).animate(scaleAndAlignCurve),
|
||||
child: new Align(
|
||||
alignment: titleAlignment,
|
||||
scale: new Tween<double>(begin: 1.5, end: 1.0).animate(scaleAndAlignCurve),
|
||||
child: new Align(
|
||||
alignment: titleAlignment,
|
||||
child: new DefaultTextStyle(style: titleStyle, child: config.title)
|
||||
)
|
||||
child: new DefaultTextStyle(style: titleStyle, child: config.title)
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
@@ -154,10 +154,8 @@ class ListItem extends StatelessWidget {
|
||||
children.add(new Container(
|
||||
margin: const EdgeInsets.only(right: 16.0),
|
||||
width: 40.0,
|
||||
child: new Align(
|
||||
alignment: FractionalOffset.centerLeft,
|
||||
child: leading
|
||||
)
|
||||
align: FractionalOffset.centerLeft,
|
||||
child: leading
|
||||
));
|
||||
}
|
||||
|
||||
@@ -188,10 +186,8 @@ class ListItem extends StatelessWidget {
|
||||
if (trailing != null) {
|
||||
children.add(new Container(
|
||||
margin: const EdgeInsets.only(left: 16.0),
|
||||
child: new Align(
|
||||
alignment: FractionalOffset.centerRight,
|
||||
child: trailing
|
||||
)
|
||||
align: FractionalOffset.centerRight,
|
||||
child: trailing
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -370,22 +370,20 @@ class RefreshIndicatorState extends State<RefreshIndicator> {
|
||||
padding: _isIndicatorAtTop
|
||||
? new EdgeInsets.only(top: config.displacement)
|
||||
: new EdgeInsets.only(bottom: config.displacement),
|
||||
child: new Align(
|
||||
alignment: _isIndicatorAtTop
|
||||
? FractionalOffset.bottomCenter
|
||||
: FractionalOffset.topCenter,
|
||||
child: new ScaleTransition(
|
||||
scale: _scaleFactor,
|
||||
child: new AnimatedBuilder(
|
||||
animation: _sizeController,
|
||||
builder: (BuildContext context, Widget child) {
|
||||
return new RefreshProgressIndicator(
|
||||
value: showIndeterminateIndicator ? null : _value.value,
|
||||
valueColor: _valueColor,
|
||||
backgroundColor: config.backgroundColor
|
||||
);
|
||||
}
|
||||
)
|
||||
align: _isIndicatorAtTop
|
||||
? FractionalOffset.bottomCenter
|
||||
: FractionalOffset.topCenter,
|
||||
child: new ScaleTransition(
|
||||
scale: _scaleFactor,
|
||||
child: new AnimatedBuilder(
|
||||
animation: _sizeController,
|
||||
builder: (BuildContext context, Widget child) {
|
||||
return new RefreshProgressIndicator(
|
||||
value: showIndeterminateIndicator ? null : _value.value,
|
||||
valueColor: _valueColor,
|
||||
backgroundColor: config.backgroundColor
|
||||
);
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -74,6 +74,7 @@ class Container extends StatelessWidget {
|
||||
/// Creates a widget that combines common painting, positioning, and sizing widgets.
|
||||
Container({
|
||||
Key key,
|
||||
this.align,
|
||||
this.padding,
|
||||
this.decoration,
|
||||
this.foregroundDecoration,
|
||||
@@ -99,6 +100,12 @@ class Container extends StatelessWidget {
|
||||
/// If null, the container will expand to fill all available space in its parent.
|
||||
final Widget child;
|
||||
|
||||
/// Align the child within the container.
|
||||
///
|
||||
/// If non-null, the container will expand to fill its parent and position its
|
||||
/// child within itself according to the given value.
|
||||
final FractionalOffset align;
|
||||
|
||||
/// Empty space to inscribe inside the decoration.
|
||||
final EdgeInsets padding;
|
||||
|
||||
@@ -133,6 +140,9 @@ class Container extends StatelessWidget {
|
||||
if (child == null && (constraints == null || !constraints.isTight))
|
||||
current = new ConstrainedBox(constraints: const BoxConstraints.expand());
|
||||
|
||||
if (align != null)
|
||||
current = new Align(alignment: align, child: current);
|
||||
|
||||
EdgeInsets effectivePadding = _paddingIncludingDecoration;
|
||||
if (effectivePadding != null)
|
||||
current = new Padding(padding: effectivePadding, child: current);
|
||||
|
||||
Reference in New Issue
Block a user