Showing
2 changed files
with
42 additions
and
10 deletions
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | * Deprecate the document argument in Printing.sharePdf() | 2 | * Deprecate the document argument in Printing.sharePdf() |
| 3 | * Add default value to alpha in PdfColor variants | 3 | * Add default value to alpha in PdfColor variants |
| 4 | * Fix Table Widget | 4 | * Fix Table Widget |
| 5 | +* Add Flexible and Spacer Widgets | ||
| 5 | 6 | ||
| 6 | # 1.3.9 | 7 | # 1.3.9 |
| 7 | * Fix Transform Widget alignment | 8 | * Fix Transform Widget alignment |
| @@ -94,7 +94,7 @@ class Flex extends MultiChildWidget { | @@ -94,7 +94,7 @@ class Flex extends MultiChildWidget { | ||
| 94 | double maxFlexFractionSoFar = 0; | 94 | double maxFlexFractionSoFar = 0; |
| 95 | 95 | ||
| 96 | for (Widget child in children) { | 96 | for (Widget child in children) { |
| 97 | - final int flex = child is Expanded ? child.flex : 0; | 97 | + final int flex = child is Flexible ? child.flex : 0; |
| 98 | totalFlex += flex; | 98 | totalFlex += flex; |
| 99 | if (flex > 0) { | 99 | if (flex > 0) { |
| 100 | final double flexFraction = childSize(child, extent) / flex; | 100 | final double flexFraction = childSize(child, extent) / flex; |
| @@ -116,7 +116,7 @@ class Flex extends MultiChildWidget { | @@ -116,7 +116,7 @@ class Flex extends MultiChildWidget { | ||
| 116 | double inflexibleSpace = 0; | 116 | double inflexibleSpace = 0; |
| 117 | double maxCrossSize = 0; | 117 | double maxCrossSize = 0; |
| 118 | for (Widget child in children) { | 118 | for (Widget child in children) { |
| 119 | - final int flex = child is Expanded ? child.flex : 0; | 119 | + final int flex = child is Flexible ? child.flex : 0; |
| 120 | totalFlex += flex; | 120 | totalFlex += flex; |
| 121 | double mainSize; | 121 | double mainSize; |
| 122 | double crossSize; | 122 | double crossSize; |
| @@ -143,7 +143,7 @@ class Flex extends MultiChildWidget { | @@ -143,7 +143,7 @@ class Flex extends MultiChildWidget { | ||
| 143 | 143 | ||
| 144 | // Size remaining (flexible) items, find the maximum cross size. | 144 | // Size remaining (flexible) items, find the maximum cross size. |
| 145 | for (Widget child in children) { | 145 | for (Widget child in children) { |
| 146 | - final int flex = child is Expanded ? child.flex : 0; | 146 | + final int flex = child is Flexible ? child.flex : 0; |
| 147 | if (flex > 0) { | 147 | if (flex > 0) { |
| 148 | maxCrossSize = | 148 | maxCrossSize = |
| 149 | math.max(maxCrossSize, childSize(child, spacePerFlex * flex)); | 149 | math.max(maxCrossSize, childSize(child, spacePerFlex * flex)); |
| @@ -219,8 +219,8 @@ class Flex extends MultiChildWidget { | @@ -219,8 +219,8 @@ class Flex extends MultiChildWidget { | ||
| 219 | double allocatedSize = 0; // Sum of the sizes of the non-flexible children. | 219 | double allocatedSize = 0; // Sum of the sizes of the non-flexible children. |
| 220 | 220 | ||
| 221 | for (Widget child in children) { | 221 | for (Widget child in children) { |
| 222 | - final int flex = child is Expanded ? child.flex : 0; | ||
| 223 | - final FlexFit fit = child is Expanded ? child.fit : FlexFit.loose; | 222 | + final int flex = child is Flexible ? child.flex : 0; |
| 223 | + final FlexFit fit = child is Flexible ? child.fit : FlexFit.loose; | ||
| 224 | if (flex > 0) { | 224 | if (flex > 0) { |
| 225 | assert(() { | 225 | assert(() { |
| 226 | final String dimension = | 226 | final String dimension = |
| @@ -277,8 +277,8 @@ class Flex extends MultiChildWidget { | @@ -277,8 +277,8 @@ class Flex extends MultiChildWidget { | ||
| 277 | canFlex && totalFlex > 0 ? (freeSpace / totalFlex) : double.nan; | 277 | canFlex && totalFlex > 0 ? (freeSpace / totalFlex) : double.nan; |
| 278 | 278 | ||
| 279 | for (Widget child in children) { | 279 | for (Widget child in children) { |
| 280 | - final int flex = child is Expanded ? child.flex : 0; | ||
| 281 | - final FlexFit fit = child is Expanded ? child.fit : FlexFit.loose; | 280 | + final int flex = child is Flexible ? child.flex : 0; |
| 281 | + final FlexFit fit = child is Flexible ? child.fit : FlexFit.loose; | ||
| 282 | if (flex > 0) { | 282 | if (flex > 0) { |
| 283 | final double maxChildExtent = canFlex | 283 | final double maxChildExtent = canFlex |
| 284 | ? (child == lastFlexChild | 284 | ? (child == lastFlexChild |
| @@ -497,15 +497,18 @@ class Column extends Flex { | @@ -497,15 +497,18 @@ class Column extends Flex { | ||
| 497 | ); | 497 | ); |
| 498 | } | 498 | } |
| 499 | 499 | ||
| 500 | -class Expanded extends SingleChildWidget { | ||
| 501 | - Expanded({ | 500 | +/// A widget that controls how a child of a [Row], [Column], or [Flex] flexes. |
| 501 | +class Flexible extends SingleChildWidget { | ||
| 502 | + Flexible({ | ||
| 502 | this.flex = 1, | 503 | this.flex = 1, |
| 503 | - this.fit = FlexFit.tight, | 504 | + this.fit = FlexFit.loose, |
| 504 | @required Widget child, | 505 | @required Widget child, |
| 505 | }) : super(child: child); | 506 | }) : super(child: child); |
| 506 | 507 | ||
| 508 | + /// The flex factor to use for this child | ||
| 507 | final int flex; | 509 | final int flex; |
| 508 | 510 | ||
| 511 | + /// How a flexible child is inscribed into the available space. | ||
| 509 | final FlexFit fit; | 512 | final FlexFit fit; |
| 510 | 513 | ||
| 511 | @override | 514 | @override |
| @@ -515,6 +518,34 @@ class Expanded extends SingleChildWidget { | @@ -515,6 +518,34 @@ class Expanded extends SingleChildWidget { | ||
| 515 | } | 518 | } |
| 516 | } | 519 | } |
| 517 | 520 | ||
| 521 | +class Expanded extends Flexible { | ||
| 522 | + Expanded({ | ||
| 523 | + int flex = 1, | ||
| 524 | + FlexFit fit = FlexFit.tight, | ||
| 525 | + @required Widget child, | ||
| 526 | + }) : super(child: child, flex: flex, fit: fit); | ||
| 527 | +} | ||
| 528 | + | ||
| 529 | +/// Spacer creates an adjustable, empty spacer that can be used to tune the | ||
| 530 | +/// spacing between widgets in a [Flex] container, like [Row] or [Column]. | ||
| 531 | +class Spacer extends StatelessWidget { | ||
| 532 | + Spacer({this.flex = 1}) | ||
| 533 | + : assert(flex != null), | ||
| 534 | + assert(flex > 0), | ||
| 535 | + super(); | ||
| 536 | + | ||
| 537 | + /// The flex factor to use in determining how much space to take up. | ||
| 538 | + final int flex; | ||
| 539 | + | ||
| 540 | + @override | ||
| 541 | + Widget build(Context context) { | ||
| 542 | + return Expanded( | ||
| 543 | + flex: flex, | ||
| 544 | + child: SizedBox.shrink(), | ||
| 545 | + ); | ||
| 546 | + } | ||
| 547 | +} | ||
| 548 | + | ||
| 518 | class ListView extends Flex { | 549 | class ListView extends Flex { |
| 519 | ListView( | 550 | ListView( |
| 520 | {Axis direction = Axis.vertical, | 551 | {Axis direction = Axis.vertical, |
-
Please register or login to post a comment