Flutter 颤振:计算CustomSingleChildLayout内的小部件大小
我尝试使用Flutter 颤振:计算CustomSingleChildLayout内的小部件大小,flutter,flutter-layout,Flutter,Flutter Layout,我尝试使用CustomSingleChildLayout如下: @override Widget build(BuildContext context) { return AnimatedBuilder( animation: widget.route.animation, builder: (context, child) { final double bottomPadding = MediaQuery.of(context).paddi
CustomSingleChildLayout
如下:
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: widget.route.animation,
builder: (context, child) {
final double bottomPadding = MediaQuery.of(context).padding.bottom;
return CustomSingleChildLayout(
delegate: _BottomPickerLayout(widget.route.animation.value,
bottomPadding: bottomPadding),
child: Material(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0),
),
),
clipBehavior: Clip.antiAlias,
elevation: 1.0,
child: AltMonth(),
),
);
},
);
这是我的deligate课程:
class _BottomPickerLayout extends SingleChildLayoutDelegate {
final double progress;
final double bottomPadding;
_BottomPickerLayout(
this.progress, {
this.bottomPadding = 0,
});
@override
Size getSize(BoxConstraints constraints) {
return super.getSize(constraints);
}
@override
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
return BoxConstraints(
minWidth: constraints.maxWidth,
maxWidth: constraints.maxWidth,
minHeight: 0.0,
maxHeight: 310 + bottomPadding,
);
}
@override
Offset getPositionForChild(Size size, Size childSize) {
final height = size.height - childSize.height * progress;
return Offset(0.0, height);
}
@override
bool shouldRelayout(covariant _BottomPickerLayout oldDelegate) {
return progress != oldDelegate.progress;
}
}
我想计算
AltMonth
小部件大小,并将其大小替换为maxHeight:310+bottomPadding,
。AltMonth小部件有不同的大小,我得到了错误。我如何计算AltMonth小部件的大小?如果您要替换它的大小,是否需要先计算它?我需要计算它的大小,因为我显示了这个小部件@nisarthreddy,您不必这样做,它完全填充了SliderBuilder
区域(我不久前使用过它,所以我可能错了…)-只需尝试一下,看看它是如何工作的删除partiallysizedbox
然后-我使用它只是为了确保两个滑动面板完全填满屏幕。不管它的子大小是多少,它都是Align
小部件的工作