Commit 03d19807 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Change `Flexible`'s default `FlexFit` (#7404)

Change `Flexible`'s default `FlexFit`

Previously, `Flexible` defaulted to `FlexFit.tight`, which forced the child to
expand to fill the available space. Now, `Flexible` defaults to
`FlexFit.loose`, which does not force the child to expand to fill the available
space.

If you want the child to expand to fill the available space, consider using
`Expanded` instead.

Fixes #5169
parent b6ac8643
...@@ -263,7 +263,6 @@ class DayPicker extends StatelessWidget { ...@@ -263,7 +263,6 @@ class DayPicker extends StatelessWidget {
) )
), ),
new Flexible( new Flexible(
fit: FlexFit.loose,
child: new CustomGrid( child: new CustomGrid(
delegate: _kDayPickerGridDelegate, delegate: _kDayPickerGridDelegate,
children: labels children: labels
...@@ -594,7 +593,6 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -594,7 +593,6 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget picker = new Flexible( Widget picker = new Flexible(
fit: FlexFit.loose,
child: new SizedBox( child: new SizedBox(
height: _kMaxDayPickerHeight, height: _kMaxDayPickerHeight,
child: _buildPicker(), child: _buildPicker(),
...@@ -644,7 +642,6 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -644,7 +642,6 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
children: <Widget>[ children: <Widget>[
header, header,
new Flexible( new Flexible(
fit: FlexFit.loose,
child: new SizedBox( child: new SizedBox(
width: _kMonthPickerLandscapeWidth, width: _kMonthPickerLandscapeWidth,
child: new Column( child: new Column(
......
...@@ -145,7 +145,6 @@ class AlertDialog extends StatelessWidget { ...@@ -145,7 +145,6 @@ class AlertDialog extends StatelessWidget {
if (content != null) { if (content != null) {
children.add(new Flexible( children.add(new Flexible(
fit: FlexFit.loose,
child: new Padding( child: new Padding(
padding: contentPadding ?? const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0), padding: contentPadding ?? const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
child: new DefaultTextStyle( child: new DefaultTextStyle(
...@@ -245,7 +244,6 @@ class SimpleDialog extends StatelessWidget { ...@@ -245,7 +244,6 @@ class SimpleDialog extends StatelessWidget {
if (children != null) { if (children != null) {
body.add(new Flexible( body.add(new Flexible(
fit: FlexFit.loose,
child: new Block( child: new Block(
padding: contentPadding ?? const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0), padding: contentPadding ?? const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0),
children: children children: children
......
...@@ -545,7 +545,7 @@ class _TabBarState extends State<TabBar> { ...@@ -545,7 +545,7 @@ class _TabBarState extends State<TabBar> {
child: wrappedTabs[index], child: wrappedTabs[index],
); );
if (!config.isScrollable) if (!config.isScrollable)
wrappedTabs[index] = new Flexible(child: wrappedTabs[index]); wrappedTabs[index] = new Expanded(child: wrappedTabs[index]);
} }
Widget tabBar = new CustomPaint( Widget tabBar = new CustomPaint(
......
...@@ -732,7 +732,6 @@ class _TimePickerDialogState extends State<_TimePickerDialog> { ...@@ -732,7 +732,6 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
children: <Widget>[ children: <Widget>[
header, header,
new Flexible( new Flexible(
fit: FlexFit.loose,
child: new Column( child: new Column(
children: <Widget>[ children: <Widget>[
new Expanded(child: picker), new Expanded(child: picker),
......
...@@ -2229,17 +2229,27 @@ class Column extends Flex { ...@@ -2229,17 +2229,27 @@ class Column extends Flex {
/// A widget that controls how a child of a [Row], [Column], or [Flex] flexes. /// A widget that controls how a child of a [Row], [Column], or [Flex] flexes.
/// ///
/// Using a [Flexible] widget gives a child of a [Row], [Column], or [Flex]
/// the flexibility to expand to fill the available space in the main axis
/// (e.g., horizontally for a [Row] or vertically for a [Column]), but, unlike
/// [Expanded], [Flexible] does not require the child to fill the available
/// space.
///
/// A [Flexible] widget must be a descendant of a [Row], [Column], or [Flex], /// A [Flexible] widget must be a descendant of a [Row], [Column], or [Flex],
/// and the path from the [Flexible] widget to its enclosing [Row], [Column], or /// and the path from the [Flexible] widget to its enclosing [Row], [Column], or
/// [Flex] must contain only [StatelessWidget]s or [StatefulWidget]s (not other /// [Flex] must contain only [StatelessWidget]s or [StatefulWidget]s (not other
/// kinds of widgets, like [RenderObjectWidget]s). /// kinds of widgets, like [RenderObjectWidget]s).
///
/// See also:
///
/// * [Expanded], which forces the child to expand to fill the available space.
class Flexible extends ParentDataWidget<Flex> { class Flexible extends ParentDataWidget<Flex> {
/// Creates a widget that controls how a child of a [Row], [Column], or [Flex] /// Creates a widget that controls how a child of a [Row], [Column], or [Flex]
/// flexes. /// flexes.
Flexible({ Flexible({
Key key, Key key,
this.flex: 1, this.flex: 1,
this.fit: FlexFit.tight, this.fit: FlexFit.loose,
@required Widget child, @required Widget child,
}) : super(key: key, child: child); }) : super(key: key, child: child);
...@@ -2292,15 +2302,19 @@ class Flexible extends ParentDataWidget<Flex> { ...@@ -2292,15 +2302,19 @@ class Flexible extends ParentDataWidget<Flex> {
/// A widget that expands a child of a [Row], [Column], or [Flex]. /// A widget that expands a child of a [Row], [Column], or [Flex].
/// ///
/// Using an [Expanded] widget to make a child of a [Row], [Column], or [Flex] /// Using an [Expanded] widget makes a child of a [Row], [Column], or [Flex]
/// expand to fill the available space in the main axis (e.g., horizontally for /// expand to fill the available space in the main axis (e.g., horizontally for
/// a [Row] or vertically for a [Column]). If multiple children are expanded, /// a [Row] or vertically for a [Column]). If multiple children are expanded,
/// the available space is divided amoung them according to the [flex] factor. /// the available space is divided amoung them according to the [flex] factor.
/// ///
/// An [Expanded] widget must be a descendant of a [Row], [Column], or [Flex], /// An [Expanded] widget must be a descendant of a [Row], [Column], or [Flex],
/// and the path from the [Flexible] widget to its enclosing [Row], [Column], or /// and the path from the [Expanded] widget to its enclosing [Row], [Column], or
/// [Flex] must contain only [StatelessWidget]s or [StatefulWidget]s (not other /// [Flex] must contain only [StatelessWidget]s or [StatefulWidget]s (not other
/// kinds of widgets, like [RenderObjectWidget]s). /// kinds of widgets, like [RenderObjectWidget]s).
///
/// See also:
///
/// * [Flexible], which does not force the child to fill the available space.
class Expanded extends Flexible { class Expanded extends Flexible {
/// Creates a widget that expands a child of a [Row], [Column], or [Flex] /// Creates a widget that expands a child of a [Row], [Column], or [Flex]
/// expand to fill the available space in the main axis. /// expand to fill the available space in the main axis.
......
...@@ -48,6 +48,19 @@ void main() { ...@@ -48,6 +48,19 @@ void main() {
expect(didReceiveTap, isTrue); expect(didReceiveTap, isTrue);
}); });
testWidgets('Flexible defaults to loose', (WidgetTester tester) async {
await tester.pumpWidget(
new Row(
children: <Widget>[
new Flexible(child: new SizedBox(width: 100.0, height: 200.0)),
],
),
);
RenderBox box = tester.renderObject(find.byType(SizedBox));
expect(box.size.width, 100.0);
});
testWidgets('Can pass null for flex', (WidgetTester tester) async { testWidgets('Can pass null for flex', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Row( new Row(
......
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