Rename Flexible to Expanded and improve docs (#6978)

This patch replaces uses of Flexible with Expanded where we're using
FlexFit.tight. We still need to think of a better name for the
FlexFit.loose variant.

Also, improve the docs for Row, Column, Flex, and RenderFlex to be more
problem-oriented and to give a complete account of the layout algorithn.

Fixes #6960
Fixes #5169
This commit is contained in:
Adam Barth
2016-11-21 23:16:43 -08:00
committed by GitHub
parent a0c567f751
commit 8ca4caa440
48 changed files with 300 additions and 198 deletions

View File

@@ -122,12 +122,12 @@ class _CalculatorState extends State<Calculator> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// Give the key-pad 3/5 of the vertical space and the display 2/5.
new Flexible(
new Expanded(
flex: 2,
child: new CalcDisplay(content: _expression.toString())
),
new Divider(height: 1.0),
new Flexible(
new Expanded(
flex: 3,
child: new KeyPad(calcState: this)
)
@@ -170,7 +170,7 @@ class KeyPad extends StatelessWidget {
child: new Material(
child: new Row(
children: <Widget>[
new Flexible(
new Expanded(
// We set flex equal to the number of columns so that the main keypad
// and the op keypad have sizes proportional to their number of
// columns.
@@ -200,7 +200,7 @@ class KeyPad extends StatelessWidget {
]
)
),
new Flexible(
new Expanded(
child: new Material(
color: themeData.backgroundColor,
child: new Column(
@@ -228,7 +228,7 @@ class KeyRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Flexible(
return new Expanded(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: this.keys
@@ -246,7 +246,7 @@ class CalcKey extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Orientation orientation = MediaQuery.of(context).orientation;
return new Flexible(
return new Expanded(
child: new InkResponse(
onTap: this.onTap,
child: new Center(

View File

@@ -83,7 +83,7 @@ class TravelDestinationItem extends StatelessWidget {
)
),
// description and share/expore buttons
new Flexible(
new Expanded(
child: new Padding(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
child: new DefaultTextStyle(

View File

@@ -28,7 +28,7 @@ class _ContactCategory extends StatelessWidget {
width: 72.0,
child: new Icon(icon, color: themeData.primaryColor)
),
new Flexible(child: new Column(children: children))
new Expanded(child: new Column(children: children))
]
)
)
@@ -53,7 +53,7 @@ class _ContactItem extends StatelessWidget {
columnChildren.add(new Text(lines.last, style: themeData.textTheme.caption));
List<Widget> rowChildren = <Widget>[
new Flexible(
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: columnChildren

View File

@@ -86,7 +86,7 @@ class _DateTimePicker extends StatelessWidget {
return new Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
new Flexible(
new Expanded(
flex: 4,
child: new _InputDropdown(
labelText: labelText,
@@ -96,7 +96,7 @@ class _DateTimePicker extends StatelessWidget {
),
),
new SizedBox(width: 12.0),
new Flexible(
new Expanded(
flex: 3,
child: new _InputDropdown(
valueText: selectedTime.toString(),

View File

@@ -45,14 +45,14 @@ class DualHeaderWithHint extends StatelessWidget {
return new Row(
children: <Widget>[
new Flexible(
new Expanded(
flex: 2,
child: new Container(
margin: const EdgeInsets.only(left: 24.0),
child: new Text(name, style: textTheme.body1.copyWith(fontSize: 15.0))
)
),
new Flexible(
new Expanded(
flex: 3,
child: new Container(
margin: const EdgeInsets.only(left: 24.0),

View File

@@ -35,7 +35,7 @@ class DateTimeItem extends StatelessWidget {
style: theme.textTheme.subhead,
child: new Row(
children: <Widget>[
new Flexible(
new Expanded(
child: new Container(
padding: const EdgeInsets.symmetric(vertical: 8.0),
decoration: new BoxDecoration(

View File

@@ -344,7 +344,7 @@ class GridListDemoState extends State<GridListDemo> {
),
body: new Column(
children: <Widget>[
new Flexible(
new Expanded(
child: new ScrollableGrid(
scrollableKey: _scrollableKey,
delegate: new FixedColumnCountGridDelegate(

View File

@@ -83,20 +83,17 @@ class IconsDemoState extends State<IconsDemo> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Flexible(
flex: 0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Text('Size', style: textStyle),
buildSizeLabel(18, textStyle),
buildSizeLabel(24, textStyle),
buildSizeLabel(36, textStyle),
buildSizeLabel(48, textStyle)
]
)
new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Text('Size', style: textStyle),
buildSizeLabel(18, textStyle),
buildSizeLabel(24, textStyle),
buildSizeLabel(36, textStyle),
buildSizeLabel(48, textStyle)
]
),
new Flexible(
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
@@ -108,7 +105,7 @@ class IconsDemoState extends State<IconsDemo> {
]
)
),
new Flexible(
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
@@ -122,7 +119,7 @@ class IconsDemoState extends State<IconsDemo> {
)
]
),
new Flexible(
new Expanded(
child: new Center(
child: new IconTheme(
data: new IconThemeData(opacity: 1.0),

View File

@@ -55,7 +55,7 @@ class PageSelectorDemo extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween
)
),
new Flexible(
new Expanded(
child: new TabBarView<IconData>(
children: icons.map((IconData icon) {
return new Container(

View File

@@ -253,7 +253,7 @@ class RecipeCard extends StatelessWidget {
tag: recipe.imagePath,
child: new Image.asset(recipe.imagePath, fit: ImageFit.contain)
),
new Flexible(
new Expanded(
child: new Row(
children: <Widget>[
new Padding(
@@ -264,7 +264,7 @@ class RecipeCard extends StatelessWidget {
height: 48.0
)
),
new Flexible(
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,

View File

@@ -81,7 +81,7 @@ class VendorItem extends StatelessWidget {
)
),
new SizedBox(width: 8.0),
new Flexible(
new Expanded(
child: new Text(vendor.name, style: ShrineTheme.of(context).vendorItemStyle)
)
]
@@ -192,7 +192,7 @@ class FeatureItem extends StatelessWidget {
child: new FeaturePriceItem(product: product)
)
),
new Flexible(
new Expanded(
child: new CustomMultiChildLayout(
delegate: new FeatureLayout(),
children: <Widget>[

View File

@@ -56,7 +56,7 @@ class OrderItem extends StatelessWidget {
)
)
),
new Flexible(
new Expanded(
child: new Text(product.name, style: theme.featureTitleStyle)
)
]

View File

@@ -110,7 +110,7 @@ class TextFieldDemoState extends State<TextFieldDemo> {
new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Flexible(
new Expanded(
child: new InputFormField(
key: _passwordFieldKey,
hintText: 'How do you log in?',
@@ -120,7 +120,7 @@ class TextFieldDemoState extends State<TextFieldDemo> {
)
),
new SizedBox(width: 16.0),
new Flexible(
new Expanded(
child: new InputFormField(
hintText: 'How do you log in?',
labelText: 'Re-type Password',

View File

@@ -29,7 +29,7 @@ class TextStyleItem extends StatelessWidget {
width: 72.0,
child: new Text(name, style: nameStyle)
),
new Flexible(
new Expanded(
child: new Text(text, style: style.copyWith(height: 1.0))
)
]

View File

@@ -91,7 +91,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
style: Theme.of(context).textTheme.subhead
)
),
new Flexible(child: demo.widget)
new Expanded(child: demo.widget)
]
);
}).toList()

View File

@@ -128,7 +128,7 @@ class GalleryDrawer extends StatelessWidget {
selected: useLightTheme,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Light')),
new Expanded(child: new Text('Light')),
new Radio<bool>(
value: true,
groupValue: useLightTheme,
@@ -144,7 +144,7 @@ class GalleryDrawer extends StatelessWidget {
selected: useLightTheme,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Dark')),
new Expanded(child: new Text('Dark')),
new Radio<bool>(
value: false,
groupValue: useLightTheme,
@@ -161,7 +161,7 @@ class GalleryDrawer extends StatelessWidget {
selected: Theme.of(context).platform == TargetPlatform.android,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Android')),
new Expanded(child: new Text('Android')),
new Radio<TargetPlatform>(
value: TargetPlatform.android,
groupValue: Theme.of(context).platform,
@@ -178,7 +178,7 @@ class GalleryDrawer extends StatelessWidget {
selected: Theme.of(context).platform == TargetPlatform.iOS,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('iOS')),
new Expanded(child: new Text('iOS')),
new Radio<TargetPlatform>(
value: TargetPlatform.iOS,
groupValue: Theme.of(context).platform,
@@ -194,7 +194,7 @@ class GalleryDrawer extends StatelessWidget {
onPressed: () { onTimeDilationChanged(timeDilation != 1.0 ? 1.0 : 20.0); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Animate Slowly')),
new Expanded(child: new Text('Animate Slowly')),
new Checkbox(
value: timeDilation != 1.0,
onChanged: (bool value) { onTimeDilationChanged(value ? 20.0 : 1.0); }
@@ -275,7 +275,7 @@ class GalleryDrawer extends StatelessWidget {
selected: showPerformanceOverlay,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Performance Overlay')),
new Expanded(child: new Text('Performance Overlay')),
new Checkbox(
value: showPerformanceOverlay,
onChanged: (bool value) { onShowPerformanceOverlayChanged(!showPerformanceOverlay); }
@@ -292,7 +292,7 @@ class GalleryDrawer extends StatelessWidget {
selected: checkerboardRasterCacheImages,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Checkerboard Raster Cache Images')),
new Expanded(child: new Text('Checkerboard Raster Cache Images')),
new Checkbox(
value: checkerboardRasterCacheImages,
onChanged: (bool value) { onCheckerboardRasterCacheImagesChanged(!checkerboardRasterCacheImages); }

View File

@@ -28,7 +28,7 @@ void main() {
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it has finished.
Finder display = find.widgetWithText(Flexible, '12');
Finder display = find.widgetWithText(Expanded, '12');
expect(display, findsOneWidget);
});
}

View File

@@ -37,7 +37,7 @@ class AdaptedGridItem extends StatelessWidget {
return new Card(
child: new Column(
children: <Widget>[
new Flexible(
new Expanded(
child: new Container(
decoration: new BoxDecoration(
backgroundColor: Colors.lightBlueAccent[100]
@@ -48,7 +48,7 @@ class AdaptedGridItem extends StatelessWidget {
margin: const EdgeInsets.only(left: 8.0),
child: new Row(
children: <Widget>[
new Flexible(
new Expanded(
child: new Text(name)
),
new IconButton(

View File

@@ -130,7 +130,7 @@ class SectorAppState extends State<SectorApp> {
mainAxisAlignment: MainAxisAlignment.spaceAround
)
),
new Flexible(
new Expanded(
child: new Container(
margin: new EdgeInsets.all(8.0),
decoration: new BoxDecoration(

View File

@@ -23,7 +23,7 @@ class Rectangle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Flexible(
return new Expanded(
child: new Container(
decoration: new BoxDecoration(backgroundColor: color)
)

View File

@@ -153,7 +153,7 @@ class StockHomeState extends State<StockHome> {
onPressed: () => _handleStockModeChange(StockMode.optimistic),
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Optimistic')),
new Expanded(child: new Text('Optimistic')),
new Radio<StockMode>(value: StockMode.optimistic, groupValue: config.configuration.stockMode, onChanged: _handleStockModeChange)
]
)
@@ -163,7 +163,7 @@ class StockHomeState extends State<StockHome> {
onPressed: () => _handleStockModeChange(StockMode.pessimistic),
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Pessimistic')),
new Expanded(child: new Text('Pessimistic')),
new Radio<StockMode>(value: StockMode.pessimistic, groupValue: config.configuration.stockMode, onChanged: _handleStockModeChange)
]
)

View File

@@ -54,22 +54,22 @@ class StockRow extends StatelessWidget {
child: new StockArrow(percentChange: stock.percentChange)
)
),
new Flexible(
new Expanded(
child: new Row(
children: <Widget>[
new Flexible(
new Expanded(
flex: 2,
child: new Text(
stock.symbol
)
),
new Flexible(
new Expanded(
child: new Text(
lastSale,
textAlign: TextAlign.right
)
),
new Flexible(
new Expanded(
child: new Text(
changeInPrice,
textAlign: TextAlign.right

View File

@@ -108,7 +108,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () => _confirmOptimismChange(),
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Everything is awesome')),
new Expanded(child: new Text('Everything is awesome')),
new Checkbox(
value: config.configuration.stockMode == StockMode.optimistic,
onChanged: (bool value) => _confirmOptimismChange()
@@ -121,7 +121,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleBackupChanged(!(config.configuration.backupMode == BackupMode.enabled)); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Back up stock list to the cloud')),
new Expanded(child: new Text('Back up stock list to the cloud')),
new Switch(
value: config.configuration.backupMode == BackupMode.enabled,
onChanged: _handleBackupChanged
@@ -134,7 +134,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowPerformanceOverlayChanged(!config.configuration.showPerformanceOverlay); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show rendering performance overlay')),
new Expanded(child: new Text('Show rendering performance overlay')),
new Switch(
value: config.configuration.showPerformanceOverlay,
onChanged: _handleShowPerformanceOverlayChanged
@@ -147,7 +147,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowSemanticsDebuggerChanged(!config.configuration.showSemanticsDebugger); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show semantics overlay')),
new Expanded(child: new Text('Show semantics overlay')),
new Switch(
value: config.configuration.showSemanticsDebugger,
onChanged: _handleShowSemanticsDebuggerChanged
@@ -164,7 +164,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowGridChanged(!config.configuration.debugShowGrid); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show material grid (for debugging)')),
new Expanded(child: new Text('Show material grid (for debugging)')),
new Switch(
value: config.configuration.debugShowGrid,
onChanged: _handleShowGridChanged
@@ -177,7 +177,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowSizesChanged(!config.configuration.debugShowSizes); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show construction lines (for debugging)')),
new Expanded(child: new Text('Show construction lines (for debugging)')),
new Switch(
value: config.configuration.debugShowSizes,
onChanged: _handleShowSizesChanged
@@ -190,7 +190,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowBaselinesChanged(!config.configuration.debugShowBaselines); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show baselines (for debugging)')),
new Expanded(child: new Text('Show baselines (for debugging)')),
new Switch(
value: config.configuration.debugShowBaselines,
onChanged: _handleShowBaselinesChanged
@@ -203,7 +203,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowLayersChanged(!config.configuration.debugShowLayers); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show layer boundaries (for debugging)')),
new Expanded(child: new Text('Show layer boundaries (for debugging)')),
new Switch(
value: config.configuration.debugShowLayers,
onChanged: _handleShowLayersChanged
@@ -216,7 +216,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowPointersChanged(!config.configuration.debugShowPointers); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show pointer hit-testing (for debugging)')),
new Expanded(child: new Text('Show pointer hit-testing (for debugging)')),
new Switch(
value: config.configuration.debugShowPointers,
onChanged: _handleShowPointersChanged
@@ -229,7 +229,7 @@ class StockSettingsState extends State<StockSettings> {
onPressed: () { _handleShowRainbowChanged(!config.configuration.debugShowRainbow); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Show repaint rainbow (for debugging)')),
new Expanded(child: new Text('Show repaint rainbow (for debugging)')),
new Switch(
value: config.configuration.debugShowRainbow,
onChanged: _handleShowRainbowChanged