public _RenderCupertinoSlider( float value, int?divisions = null, Color activeColor = null, ValueChanged <float> onChanged = null, ValueChanged <float> onChangeStart = null, ValueChanged <float> onChangeEnd = null, TickerProvider vsync = null ) : base(additionalConstraints: BoxConstraints.tightFor(width: SliderUtils._kSliderWidth, height: SliderUtils._kSliderHeight)) { D.assert(value >= 0.0f && value <= 1.0f); this._value = value; this._divisions = divisions; this._activeColor = activeColor; this._onChanged = onChanged; this._drag = new HorizontalDragGestureRecognizer(); this._drag.onStart = this._handleDragStart; this._drag.onUpdate = this._handleDragUpdate; this._drag.onEnd = this._handleDragEnd; this._position = new AnimationController( value: value, duration: SliderUtils._kDiscreteTransitionDuration, vsync: vsync ); this._position.addListener(this.markNeedsPaint); }
public override Widget build(BuildContext context) { return(new Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: colors.Select <_NamedColor, Widget>(namedColor => { return new RawMaterialButton( onPressed: () => { onChanged(namedColor.color); }, constraints: BoxConstraints.tightFor( 32.0f, 32.0f ), fillColor: namedColor.color, shape: new CircleBorder( new BorderSide( namedColor.color == selectedColor ? Colors.black : new Color(0xFFD5D7DA), 2.0f ) ), child: new Container( ) ); }).ToList() )); }
public _RenderCupertinoSwitch( bool value, Color activeColor, TextDirection textDirection, TickerProvider vsync, ValueChanged <bool> onChanged = null, DragStartBehavior dragStartBehavior = DragStartBehavior.start ) : base(additionalConstraints: BoxConstraints.tightFor( width: CupertinoSwitchUtils._kSwitchWidth, height: CupertinoSwitchUtils._kSwitchHeight) ) { D.assert(activeColor != null); D.assert(vsync != null); this._value = value; this._activeColor = activeColor; this._onChanged = onChanged; this._textDirection = textDirection; this._vsync = vsync; this._tap = new TapGestureRecognizer() { onTapDown = this._handleTapDown, onTap = this._handleTap, onTapUp = this._handleTapUp, onTapCancel = this._handleTapCancel, }; this._drag = new HorizontalDragGestureRecognizer() { onStart = this._handleDragStart, onUpdate = this._handleDragUpdate, onEnd = this._handleDragEnd, dragStartBehavior = dragStartBehavior }; this._positionController = new AnimationController( duration: CupertinoSwitchUtils._kToggleDuration, value: value ? 1.0f : 0.0f, vsync: vsync ); this._position = new CurvedAnimation( parent: this._positionController, curve: Curves.linear ); this._position.addListener(this.markNeedsPaint); this._position.addStatusListener(this._handlePositionStateChanged); this._reactionController = new AnimationController( duration: CupertinoSwitchUtils._kReactionDuration, vsync: vsync ); this._reaction = new CurvedAnimation( parent: this._reactionController, curve: Curves.ease ); this._reaction.addListener(this.markNeedsPaint); }
protected override void performLayout() { BoxConstraints constraints = this.constraints; float maxHeight = CupertinoSegmentedControlsUtils._kMinSegmentedControlHeight; float childWidth = constraints.minWidth / childCount; foreach (RenderBox child in getChildrenAsList()) { childWidth = Mathf.Max(childWidth, child.getMaxIntrinsicWidth(float.PositiveInfinity)); } childWidth = Mathf.Min(childWidth, constraints.maxWidth / childCount); RenderBox child1 = firstChild; while (child1 != null) { float boxHeight = child1.getMaxIntrinsicHeight(childWidth); maxHeight = Mathf.Max(maxHeight, boxHeight); child1 = childAfter(child1); } constraints.constrainHeight(maxHeight); BoxConstraints childConstraints = BoxConstraints.tightFor( width: childWidth, height: maxHeight ); child1 = firstChild; while (child1 != null) { child1.layout(childConstraints, parentUsesSize: true); child1 = childAfter(child1); } switch (textDirection) { case TextDirection.rtl: _layoutRects( childBefore, lastChild, firstChild ); break; case TextDirection.ltr: _layoutRects( childAfter, firstChild, lastChild ); break; } size = constraints.constrain(new Size(childWidth * childCount, maxHeight)); }
Size _sizeForConstraints(BoxConstraints constraints) { constraints = BoxConstraints.tightFor( _width, _height ).enforce(constraints); return(constraints.smallest); }
protected override void performLayout() { BoxConstraints constraints = this.constraints; float childWidth = (constraints.minWidth - totalSeparatorWidth) / childCount; float maxHeight = CupertinoSlidingSegmentedControlsUtils._kMinSegmentedControlHeight; foreach (RenderBox child1 in getChildrenAsList()) { childWidth = Mathf.Max(childWidth, child1.getMaxIntrinsicWidth(float.PositiveInfinity) + 2 * CupertinoSlidingSegmentedControlsUtils._kSegmentMinPadding); } childWidth = Mathf.Min( childWidth, (constraints.maxWidth - totalSeparatorWidth) / childCount ); RenderBox child = firstChild; while (child != null) { float boxHeight = child.getMaxIntrinsicHeight(childWidth); maxHeight = Mathf.Max(maxHeight, boxHeight); child = childAfter(child); } constraints.constrainHeight(maxHeight); BoxConstraints childConstraints = BoxConstraints.tightFor( width: childWidth, height: maxHeight ); // Layout children. child = firstChild; while (child != null) { child.layout(childConstraints, parentUsesSize: true); child = childAfter(child); } float start = 0; child = firstChild; while (child != null) { _SlidingSegmentedControlContainerBoxParentData childParentData = child.parentData as _SlidingSegmentedControlContainerBoxParentData; Offset childOffset = new Offset(start, 0); childParentData.offset = childOffset; start += child.size.width + CupertinoSlidingSegmentedControlsUtils._kSeparatorWidth + CupertinoSlidingSegmentedControlsUtils._kSeparatorInset.horizontal; child = childAfter(child); } size = constraints.constrain(new Size(childWidth * childCount + totalSeparatorWidth, maxHeight)); }
Widget _buildVerticalControls() { if (widget.controlsBuilder != null) { return(widget.controlsBuilder( context, onStepContinue: widget.onStepContinue, onStepCancel: widget.onStepCancel )); } Color cancelColor = null; switch (Theme.of(context).brightness) { case Brightness.light: cancelColor = Colors.black54; break; case Brightness.dark: cancelColor = Colors.white70; break; } D.assert(cancelColor != null); ThemeData themeData = Theme.of(context); MaterialLocalizations localizations = MaterialLocalizations.of(context); return(new Container( margin: EdgeInsets.only(top: 16.0f), child: new ConstrainedBox( constraints: BoxConstraints.tightFor(height: 48.0f), child: new Row( children: new List <Widget> { new FlatButton( onPressed: widget.onStepContinue, color: _isDark() ? themeData.backgroundColor : themeData.primaryColor, textColor: Colors.white, textTheme: ButtonTextTheme.normal, child: new Text(localizations.continueButtonLabel) ), new Container( margin: EdgeInsets.only(8.0f), child: new FlatButton( onPressed: widget.onStepCancel, textColor: cancelColor, textTheme: ButtonTextTheme.normal, child: new Text(localizations.cancelButtonLabel) ) ) } ) ) )); }
Widget _buildIndicator(float animationValue) { return(new Container( constraints: BoxConstraints.tightFor( float.PositiveInfinity, 2 ), child: new CustomPaint( painter: new _CustomProgressPainter(this.widget.backgroundColor, this.widget.valueColor?.value ?? CColors.PrimaryBlue, this.widget.value, animationValue ) ) )); }
Size _sizeForConstraints(BoxConstraints constraints) { constraints = BoxConstraints.tightFor( _width, _height ).enforce(constraints); if (_image == null) { return(constraints.smallest); } return(constraints.constrainSizeAndAttemptToPreserveAspectRatio(new Size( (_image.width / _scale), (_image.height / _scale) ))); }
public override void performLayout(Size size) { layoutChild( track, BoxConstraints.tightFor( width: size.width - 30f, height: size.height / 5f ) ); positionChild(track, new Offset(15.0f, size.height * 0.4f)); layoutChild( thumb, BoxConstraints.tightFor(width: 5f, height: size.height / 4) ); positionChild(thumb, new Offset(0f, size.height * 0.4f)); layoutChild( gestureContainer, BoxConstraints.tightFor(width: size.width, height: size.height) ); positionChild(gestureContainer, Offset.zero); }
public Container( Key key = null, AlignmentGeometry alignment = null, EdgeInsetsGeometry padding = null, Color color = null, Decoration decoration = null, Decoration foregroundDecoration = null, float?width = null, float?height = null, BoxConstraints constraints = null, EdgeInsetsGeometry margin = null, Matrix4 transform = null, Widget child = null, Clip clipBehavior = Clip.none ) : base(key: key) { D.assert(margin == null || margin.isNonNegative); D.assert(padding == null || padding.isNonNegative); D.assert(decoration == null || decoration.debugAssertIsValid()); D.assert(constraints == null || constraints.debugAssertIsValid()); D.assert(color == null || decoration == null, () => "Cannot provide both a color and a decoration\n" + "The color argument is just a shorthand for \"decoration: new BoxDecoration(color: color)\"." ); D.assert(clipBehavior != null); this.alignment = alignment; this.padding = padding; this.foregroundDecoration = foregroundDecoration; this.color = color; this.decoration = decoration;// ?? (color != null ? new BoxDecoration(color) : null); this.constraints = (width != null || height != null) ? (constraints != null ? constraints.tighten(width, height) : BoxConstraints.tightFor(width, height)) : constraints; this.margin = margin; this.transform = transform; this.child = child; this.clipBehavior = clipBehavior; }
public AnimatedContainer( Key key = null, AlignmentGeometry alignment = null, EdgeInsetsGeometry padding = null, Color color = null, Decoration decoration = null, Decoration foregroundDecoration = null, float?width = null, float?height = null, BoxConstraints constraints = null, EdgeInsetsGeometry margin = null, Matrix4 transform = null, Widget child = null, Curve curve = null, TimeSpan?duration = null, VoidCallback onEnd = null ) : base(key: key, curve: curve ?? Curves.linear, duration: duration, onEnd: onEnd) { D.assert(duration != null); D.assert(margin == null || margin.isNonNegative); D.assert(padding == null || padding.isNonNegative); D.assert(decoration == null || decoration.debugAssertIsValid()); D.assert(constraints == null || constraints.debugAssertIsValid()); D.assert(color == null || decoration == null, () => "Cannot provide both a color and a decoration\n" + "The color argument is just a shorthand for \"decoration: new BoxDecoration(backgroundColor: color)\"."); this.alignment = alignment; this.padding = padding; this.foregroundDecoration = foregroundDecoration; this.margin = margin; this.transform = transform; this.child = child; this.decoration = decoration ?? (color != null ? new BoxDecoration(color: color) : null); this.constraints = (width != null || height != null) ? constraints?.tighten(width: width, height: height) ?? BoxConstraints.tightFor(width: width, height: height) : constraints; }
public _RenderCupertinoSwitch( bool value, Color activeColor, Color trackColor = null, TextDirection?textDirection = null, ValueChanged <bool> onChanged = null, _CupertinoSwitchState state = null ) : base(additionalConstraints: BoxConstraints.tightFor( width: CupertinoSwitchUtils._kSwitchWidth, height: CupertinoSwitchUtils._kSwitchHeight) ) { D.assert(state != null); _value = value; _activeColor = activeColor; _trackColor = trackColor; _onChanged = onChanged; _textDirection = textDirection; _state = state; state.position.addListener(markNeedsPaint); state._reaction.addListener(markNeedsPaint); }
public override Widget build(BuildContext context) { return(new GestureDetector( onTap: () => { Navigator.push(context, new MaterialPageRoute( builder: (context3 => { return new HabitEditor(); }) )); }, child: new LayoutBuilder( builder: ((buildContext, constraints) => { return new Container( constraints: BoxConstraints.tightFor(width: mHabitWidth), height: HabitHeight, padding: EdgeInsets.only(left: 5, top: 3, bottom: 2, right: 5), margin: EdgeInsets.symmetric(horizontal: Habits.Padding / 2, vertical: Habits.VerticalPadding / 2), decoration: new BoxDecoration( color: Colors.white10, borderRadius: BorderRadius.all(Radius.circular(4)) ), alignment: Alignment.center, child: new Row( mainAxisAlignment: MainAxisAlignment.center, children: new List <Widget>() { new Text("创建习惯", style: new TextStyle(color: Colors.white, fontSize: 16)) } ) ); }) ) )); }
public Container( Key key = null, Alignment alignment = null, EdgeInsets padding = null, Color color = null, Decoration decoration = null, Decoration forgroundDecoration = null, double?width = null, double?height = null, BoxConstraints constraints = null, EdgeInsets margin = null, Matrix3 transfrom = null, Widget child = null ) : base(key) { D.assert(margin == null || margin.isNonNegative); D.assert(padding == null || padding.isNonNegative); D.assert(decoration == null || decoration.debugAssertIsValid()); D.assert(constraints == null || constraints.debugAssertIsValid()); D.assert(color == null || decoration == null, "Cannot provide both a color and a decoration\n" + "The color argument is just a shorthand for \"decoration: new BoxDecoration(color: color)\"." ); this.alignment = alignment; this.padding = padding; this.foregroundDecoration = forgroundDecoration; this.margin = margin; this.transform = transfrom; this.child = child; this.decoration = decoration ?? (color != null ? new BoxDecoration(color) : null); this.constraints = (width != null || height != null) ? (constraints != null ? constraints.tighten(width, height) : BoxConstraints.tightFor(width, height)) : constraints; }
public override Widget build(BuildContext context) { D.assert(MaterialD.debugCheckHasMaterialLocalizations(context)); ThemeData themeData = Theme.of(context); ScaffoldState scaffold = Scaffold.of(context, nullOk: true); ModalRoute parentRoute = ModalRoute.of(context); bool hasDrawer = scaffold?.hasDrawer ?? false; bool hasEndDrawer = scaffold?.hasEndDrawer ?? false; bool canPop = parentRoute?.canPop ?? false; bool useCloseButton = parentRoute is PageRoute && ((PageRoute)parentRoute).fullscreenDialog; IconThemeData appBarIconTheme = this.widget.iconTheme ?? themeData.primaryIconTheme; TextStyle centerStyle = this.widget.textTheme?.title ?? themeData.primaryTextTheme.title; TextStyle sideStyle = this.widget.textTheme?.body1 ?? themeData.primaryTextTheme.body1; if (this.widget.toolbarOpacity != 1.0f) { float opacity = new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(this.widget.toolbarOpacity); if (centerStyle?.color != null) { centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity)); } if (sideStyle?.color != null) { sideStyle = sideStyle.copyWith(color: sideStyle.color.withOpacity(opacity)); } appBarIconTheme = appBarIconTheme.copyWith( opacity: opacity * (appBarIconTheme.opacity ?? 1.0f) ); } Widget leading = this.widget.leading; if (leading == null && this.widget.automaticallyImplyLeading) { if (hasDrawer) { leading = new IconButton( icon: new Icon(Icons.menu), onPressed: this._handleDrawerButton, tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip); } else { if (canPop) { leading = useCloseButton ? (Widget) new CloseButton() : new BackButton(); } } } if (leading != null) { leading = new ConstrainedBox( constraints: BoxConstraints.tightFor(width: AppBarUtils._kLeadingWidth), child: leading); } Widget title = this.widget.title; if (title != null) { title = new DefaultTextStyle( style: centerStyle, softWrap: false, overflow: TextOverflow.ellipsis, child: title); } Widget actions = null; if (this.widget.actions != null && this.widget.actions.isNotEmpty()) { actions = new Row( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: this.widget.actions); } else if (hasEndDrawer) { actions = new IconButton( icon: new Icon(Icons.menu), onPressed: this._handleDrawerButtonEnd, tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip); } Widget toolbar = new NavigationToolbar( leading: leading, middle: title, trailing: actions, centerMiddle: this.widget._getEffectiveCenterTitle(themeData).Value, middleSpacing: this.widget.titleSpacing); Widget appBar = new ClipRect( child: new CustomSingleChildLayout( layoutDelegate: new _ToolbarContainerLayout(), child: IconTheme.merge( data: appBarIconTheme, child: new DefaultTextStyle( style: sideStyle, child: toolbar) ) ) ); if (this.widget.bottom != null) { appBar = new Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: new List <Widget> { new Flexible( child: new ConstrainedBox( constraints: new BoxConstraints(maxHeight: Constants.kToolbarHeight), child: appBar ) ), this.widget.bottomOpacity == 1.0f ? (Widget)this.widget.bottom : new Opacity( opacity: new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(this.widget .bottomOpacity), child: this.widget.bottom ) } ); } if (this.widget.primary) { appBar = new SafeArea( top: true, child: appBar); } appBar = new Align( alignment: Alignment.topCenter, child: appBar); if (this.widget.flexibleSpace != null) { appBar = new Stack( fit: StackFit.passthrough, children: new List <Widget> { this.widget.flexibleSpace, appBar } ); } Brightness brightness = this.widget.brightness ?? themeData.primaryColorBrightness; SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark; return(new AnnotatedRegion <SystemUiOverlayStyle>( value: overlayStyle, child: new Material( color: this.widget.backgroundColor ?? themeData.primaryColor, elevation: this.widget.elevation, child: appBar ))); }
protected override void performLayout() { BoxConstraints constraints = this.constraints; D.assert(() => { switch (mainAxis) { case Axis.horizontal: if (!constraints.hasBoundedWidth) { return(true); } break; case Axis.vertical: if (!constraints.hasBoundedHeight) { return(true); } break; } throw new UIWidgetsError(new List <DiagnosticsNode> { new ErrorSummary("RenderListBody must have unlimited space along its main axis."), new ErrorDescription( "RenderListBody does not clip or resize its children, so it must be " + "placed in a parent that does not constrain the main axis." ), new ErrorHint( "You probably want to put the RenderListBody inside a " + "RenderViewport with a matching main axis." ) }); }); D.assert(() => { switch (mainAxis) { case Axis.horizontal: if (constraints.hasBoundedHeight) { return(true); } break; case Axis.vertical: if (constraints.hasBoundedWidth) { return(true); } break; } throw new UIWidgetsError(new List <DiagnosticsNode> { new ErrorSummary("RenderListBody must have a bounded constraint for its cross axis."), new ErrorDescription( "RenderListBody forces its children to expand to fit the RenderListBody's container, " + "so it must be placed in a parent that constrains the cross " + "axis to a finite dimension." ), // TODO(jacobr): this hint is a great candidate to promote to being an // automated quick fix in the future. new ErrorHint( "If you are attempting to nest a RenderListBody with " + "one direction inside one of another direction, you will want to " + "wrap the inner one inside a box that fixes the dimension in that direction, " + "for example, a RenderIntrinsicWidth or RenderIntrinsicHeight object. " + "This is relatively expensive, however." // (that's why we don't do it automatically) ) }); }); float mainAxisExtent = 0.0f; RenderBox child = firstChild; BoxConstraints innerConstraints; float position; switch (axisDirection) { case AxisDirection.right: innerConstraints = BoxConstraints.tightFor(height: constraints.maxHeight); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; childParentData.offset = new Offset(mainAxisExtent, 0.0f); mainAxisExtent += child.size.width; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } size = constraints.constrain(new Size(mainAxisExtent, constraints.maxHeight)); break; case AxisDirection.left: innerConstraints = BoxConstraints.tightFor(height: constraints.maxHeight); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; mainAxisExtent += child.size.width; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } position = 0.0f; child = firstChild; while (child != null) { ListBodyParentData childParentData = (ListBodyParentData)child.parentData; position += child.size.width; childParentData.offset = new Offset((mainAxisExtent - position), 0.0f); D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } size = constraints.constrain(new Size(mainAxisExtent, constraints.maxHeight)); break; case AxisDirection.down: innerConstraints = BoxConstraints.tightFor(width: constraints.maxWidth); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; childParentData.offset = new Offset(0.0f, mainAxisExtent); mainAxisExtent += child.size.height; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } size = constraints.constrain(new Size(constraints.maxWidth, mainAxisExtent)); break; case AxisDirection.up: innerConstraints = BoxConstraints.tightFor(width: constraints.maxWidth); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; mainAxisExtent += child.size.height; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } position = 0.0f; child = firstChild; while (child != null) { ListBodyParentData childParentData = (ListBodyParentData)child.parentData; position += child.size.height; childParentData.offset = new Offset(0.0f, mainAxisExtent - position); D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } size = constraints.constrain(new Size(constraints.maxWidth, mainAxisExtent)); break; } D.assert(size.isFinite); }
protected override void performLayout() { D.assert(() => { switch (this.mainAxis) { case Axis.horizontal: if (!this.constraints.hasBoundedWidth) { return(true); } break; case Axis.vertical: if (!this.constraints.hasBoundedHeight) { return(true); } break; } throw new UIWidgetsError( "RenderListBody must have unlimited space along its main axis.\n" + "RenderListBody does not clip or resize its children, so it must be " + "placed in a parent that does not constrain the main " + "axis. You probably want to put the RenderListBody inside a " + "RenderViewport with a matching main axis."); }); D.assert(() => { switch (this.mainAxis) { case Axis.horizontal: if (this.constraints.hasBoundedHeight) { return(true); } break; case Axis.vertical: if (this.constraints.hasBoundedWidth) { return(true); } break; } throw new UIWidgetsError( "RenderListBody must have a bounded constraint for its cross axis.\n" + "RenderListBody forces its children to expand to fit the RenderListBody\"s container, " + "so it must be placed in a parent that constrains the cross " + "axis to a finite dimension. If you are attempting to nest a RenderListBody with " + "one direction inside one of another direction, you will want to " + "wrap the inner one inside a box that fixes the dimension in that direction, " + "for example, a RenderIntrinsicWidth or RenderIntrinsicHeight object. " + "This is relatively expensive, however." ); }); float mainAxisExtent = 0.0f; RenderBox child = this.firstChild; BoxConstraints innerConstraints; float position; switch (this.axisDirection) { case AxisDirection.right: innerConstraints = BoxConstraints.tightFor(height: this.constraints.maxHeight); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; childParentData.offset = new Offset(mainAxisExtent, 0.0f); mainAxisExtent += child.size.width; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } this.size = this.constraints.constrain(new Size(mainAxisExtent, this.constraints.maxHeight)); break; case AxisDirection.left: innerConstraints = BoxConstraints.tightFor(height: this.constraints.maxHeight); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; mainAxisExtent += child.size.width; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } position = 0.0f; child = this.firstChild; while (child != null) { ListBodyParentData childParentData = (ListBodyParentData)child.parentData; position += child.size.width; childParentData.offset = new Offset((mainAxisExtent - position), 0.0f); D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } this.size = this.constraints.constrain(new Size(mainAxisExtent, this.constraints.maxHeight)); break; case AxisDirection.down: innerConstraints = BoxConstraints.tightFor(width: this.constraints.maxWidth); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; childParentData.offset = new Offset(0.0f, mainAxisExtent); mainAxisExtent += child.size.height; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } this.size = this.constraints.constrain(new Size(this.constraints.maxWidth, mainAxisExtent)); break; case AxisDirection.up: innerConstraints = BoxConstraints.tightFor(width: this.constraints.maxWidth); while (child != null) { child.layout(innerConstraints, parentUsesSize: true); ListBodyParentData childParentData = (ListBodyParentData)child.parentData; mainAxisExtent += child.size.height; D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } position = 0.0f; child = this.firstChild; while (child != null) { ListBodyParentData childParentData = (ListBodyParentData)child.parentData; position += child.size.height; childParentData.offset = new Offset(0.0f, mainAxisExtent - position); D.assert(child.parentData == childParentData); child = childParentData.nextSibling; } this.size = this.constraints.constrain(new Size(this.constraints.maxWidth, mainAxisExtent)); break; } D.assert(this.size.isFinite); }
protected override void performLayout() { int rows = this.rows; int columns = this.columns; D.assert(this._children.Count == rows * columns); if (rows * columns == 0) { this.size = this.constraints.constrain(new Size(0.0f, 0.0f)); return; } List <float> widths = this._computeColumnWidths(this.constraints); List <float> positions = new List <float>(); float tableWidth = 0.0f; positions.Add(0.0f); for (int x = 1; x < columns; x++) { positions.Add(positions[x - 1] + widths[x - 1]); } this._columnLefts = positions; tableWidth = positions.Last() + widths.Last(); D.assert(!positions.Any((float value) => { return(value == null); })); this._rowTops.Clear(); this._baselineDistance = null; float rowTop = 0.0f; for (int y = 0; y < rows; y++) { this._rowTops.Add(rowTop); float rowHeight = 0.0f; bool haveBaseline = false; float beforeBaselineDistance = 0.0f; float afterBaselineDistance = 0.0f; List <float?> baselines = new List <float?>(); for (int i = 0; i < columns; i++) { baselines.Add(null); } for (int x = 0; x < columns; x++) { int xy = x + y * columns; RenderBox child = this._children[xy]; if (child != null) { TableCellParentData childParentData = (TableCellParentData)child.parentData; D.assert(childParentData != null); childParentData.x = x; childParentData.y = y; switch (childParentData.verticalAlignment ?? this.defaultVerticalAlignment) { case TableCellVerticalAlignment.baseline: { D.assert(this.textBaseline != null); child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true); float?childBaseline = child.getDistanceToBaseline(this.textBaseline.Value, onlyReal: true); if (childBaseline != null) { beforeBaselineDistance = Mathf.Max(beforeBaselineDistance, childBaseline.Value); afterBaselineDistance = Mathf.Max(afterBaselineDistance, child.size.height - childBaseline.Value); baselines[x] = childBaseline.Value; haveBaseline = true; } else { rowHeight = Mathf.Max(rowHeight, child.size.height); childParentData.offset = new Offset(positions[x], rowTop); } break; } case TableCellVerticalAlignment.top: case TableCellVerticalAlignment.middle: case TableCellVerticalAlignment.bottom: { child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true); rowHeight = Mathf.Max(rowHeight, child.size.height); break; } case TableCellVerticalAlignment.fill: { break; } } } } if (haveBaseline) { if (y == 0) { this._baselineDistance = beforeBaselineDistance; } rowHeight = Mathf.Max(rowHeight, beforeBaselineDistance + afterBaselineDistance); } for (int x = 0; x < columns; x++) { int xy = x + y * columns; RenderBox child = this._children[xy]; if (child != null) { TableCellParentData childParentData = (TableCellParentData)child.parentData; switch (childParentData.verticalAlignment ?? this.defaultVerticalAlignment) { case TableCellVerticalAlignment.baseline: { if (baselines[x] != null) { childParentData.offset = new Offset(positions[x], rowTop + beforeBaselineDistance - baselines[x].Value); } break; } case TableCellVerticalAlignment.top: { childParentData.offset = new Offset(positions[x], rowTop); break; } case TableCellVerticalAlignment.middle: { childParentData.offset = new Offset(positions[x], rowTop + (rowHeight - child.size.height) / 2.0f); break; } case TableCellVerticalAlignment.bottom: { childParentData.offset = new Offset(positions[x], rowTop + rowHeight - child.size.height); break; } case TableCellVerticalAlignment.fill: { child.layout(BoxConstraints.tightFor(width: widths[x], height: rowHeight)); childParentData.offset = new Offset(positions[x], rowTop); break; } } } } rowTop += rowHeight; } this._rowTops.Add(rowTop); this.size = this.constraints.constrain(new Size(tableWidth, rowTop)); D.assert(this._rowTops.Count == rows + 1); }