How to have dynamic height in CustomMultiChildLayout?
I created a CustomMultiChildLayout
in order to customize the positions of its children. Then tried to put CustomMultiChildLayout
into a Container
, with BoxConstraints(maxHeight: 500)
, then the CustomMultiChildLayout
has always the maxHeight 500 as height. It cannot adjust its height according to its children.
So how can I have dynamic height for my CustomMultiChildLayout
? If this is not possible, are there any other ways to implement this layout?
Background:
I defined 3 widgets, each of them is a Container
, and I need to customize their positions.
SellerWidget should be positioned in the middle of two other widgets.
Please refer to this image:
Here's my code:
class ProductComboWidget extends StatelessWidget {
final Product _product;
ProductComboWidget(this._product);
@override
Widget build(BuildContext context) {
return Container(
constraints: BoxConstraints(maxHeight: 500),
child: CustomMultiChildLayout(
delegate: _TitleInfoLayout(),
children: <Widget>[
LayoutId(
id: _TitleInfoLayout.title,
child: ProductTitleWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.info,
child: ProductInfoWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.seller,
child: SellerWidget(_product.seller)
),
],
),
);
}
}
class _TitleInfoLayout extends MultiChildLayoutDelegate {
static const String title = 'title';
static const String info = 'info';
static const String seller = 'seller';
@override
void performLayout(Size size) {
final Size titleSize = layoutChild(title, BoxConstraints(maxWidth: size.width));
positionChild(title, Offset(0, 0));
layoutChild(info, BoxConstraints(maxWidth: size.width));
positionChild(info, Offset(0, titleSize.height));
final Size sellerSize = layoutChild(seller, BoxConstraints());
positionChild(seller, Offset(size.width - sellerSize.width - 20, titleSize.height - sellerSize.height / 2));
}
@override
bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) {
return true;
}
}
Actual result:
The height of CustomMultiChildLayout
always equals to BoxConstraint.maxHeight, it cannot adjust its height according to its children.
Please refer to this image:
There is a useless empty space on the bottom of this widget.
Expected result:
Have its height adapted to its children, like other widgets.
flutter flutter-layout
add a comment |
I created a CustomMultiChildLayout
in order to customize the positions of its children. Then tried to put CustomMultiChildLayout
into a Container
, with BoxConstraints(maxHeight: 500)
, then the CustomMultiChildLayout
has always the maxHeight 500 as height. It cannot adjust its height according to its children.
So how can I have dynamic height for my CustomMultiChildLayout
? If this is not possible, are there any other ways to implement this layout?
Background:
I defined 3 widgets, each of them is a Container
, and I need to customize their positions.
SellerWidget should be positioned in the middle of two other widgets.
Please refer to this image:
Here's my code:
class ProductComboWidget extends StatelessWidget {
final Product _product;
ProductComboWidget(this._product);
@override
Widget build(BuildContext context) {
return Container(
constraints: BoxConstraints(maxHeight: 500),
child: CustomMultiChildLayout(
delegate: _TitleInfoLayout(),
children: <Widget>[
LayoutId(
id: _TitleInfoLayout.title,
child: ProductTitleWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.info,
child: ProductInfoWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.seller,
child: SellerWidget(_product.seller)
),
],
),
);
}
}
class _TitleInfoLayout extends MultiChildLayoutDelegate {
static const String title = 'title';
static const String info = 'info';
static const String seller = 'seller';
@override
void performLayout(Size size) {
final Size titleSize = layoutChild(title, BoxConstraints(maxWidth: size.width));
positionChild(title, Offset(0, 0));
layoutChild(info, BoxConstraints(maxWidth: size.width));
positionChild(info, Offset(0, titleSize.height));
final Size sellerSize = layoutChild(seller, BoxConstraints());
positionChild(seller, Offset(size.width - sellerSize.width - 20, titleSize.height - sellerSize.height / 2));
}
@override
bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) {
return true;
}
}
Actual result:
The height of CustomMultiChildLayout
always equals to BoxConstraint.maxHeight, it cannot adjust its height according to its children.
Please refer to this image:
There is a useless empty space on the bottom of this widget.
Expected result:
Have its height adapted to its children, like other widgets.
flutter flutter-layout
the size of the parent cannot depend on the sizes of the children. docs.flutter.io/flutter/widgets/…
– Ahmed
Jan 2 at 3:50
I think it's lot easier to achieve what you are trying to do with just Rows and Culomns.
– dshukertjr
Jan 2 at 4:06
add a comment |
I created a CustomMultiChildLayout
in order to customize the positions of its children. Then tried to put CustomMultiChildLayout
into a Container
, with BoxConstraints(maxHeight: 500)
, then the CustomMultiChildLayout
has always the maxHeight 500 as height. It cannot adjust its height according to its children.
So how can I have dynamic height for my CustomMultiChildLayout
? If this is not possible, are there any other ways to implement this layout?
Background:
I defined 3 widgets, each of them is a Container
, and I need to customize their positions.
SellerWidget should be positioned in the middle of two other widgets.
Please refer to this image:
Here's my code:
class ProductComboWidget extends StatelessWidget {
final Product _product;
ProductComboWidget(this._product);
@override
Widget build(BuildContext context) {
return Container(
constraints: BoxConstraints(maxHeight: 500),
child: CustomMultiChildLayout(
delegate: _TitleInfoLayout(),
children: <Widget>[
LayoutId(
id: _TitleInfoLayout.title,
child: ProductTitleWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.info,
child: ProductInfoWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.seller,
child: SellerWidget(_product.seller)
),
],
),
);
}
}
class _TitleInfoLayout extends MultiChildLayoutDelegate {
static const String title = 'title';
static const String info = 'info';
static const String seller = 'seller';
@override
void performLayout(Size size) {
final Size titleSize = layoutChild(title, BoxConstraints(maxWidth: size.width));
positionChild(title, Offset(0, 0));
layoutChild(info, BoxConstraints(maxWidth: size.width));
positionChild(info, Offset(0, titleSize.height));
final Size sellerSize = layoutChild(seller, BoxConstraints());
positionChild(seller, Offset(size.width - sellerSize.width - 20, titleSize.height - sellerSize.height / 2));
}
@override
bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) {
return true;
}
}
Actual result:
The height of CustomMultiChildLayout
always equals to BoxConstraint.maxHeight, it cannot adjust its height according to its children.
Please refer to this image:
There is a useless empty space on the bottom of this widget.
Expected result:
Have its height adapted to its children, like other widgets.
flutter flutter-layout
I created a CustomMultiChildLayout
in order to customize the positions of its children. Then tried to put CustomMultiChildLayout
into a Container
, with BoxConstraints(maxHeight: 500)
, then the CustomMultiChildLayout
has always the maxHeight 500 as height. It cannot adjust its height according to its children.
So how can I have dynamic height for my CustomMultiChildLayout
? If this is not possible, are there any other ways to implement this layout?
Background:
I defined 3 widgets, each of them is a Container
, and I need to customize their positions.
SellerWidget should be positioned in the middle of two other widgets.
Please refer to this image:
Here's my code:
class ProductComboWidget extends StatelessWidget {
final Product _product;
ProductComboWidget(this._product);
@override
Widget build(BuildContext context) {
return Container(
constraints: BoxConstraints(maxHeight: 500),
child: CustomMultiChildLayout(
delegate: _TitleInfoLayout(),
children: <Widget>[
LayoutId(
id: _TitleInfoLayout.title,
child: ProductTitleWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.info,
child: ProductInfoWidget(_product)
),
LayoutId(
id: _TitleInfoLayout.seller,
child: SellerWidget(_product.seller)
),
],
),
);
}
}
class _TitleInfoLayout extends MultiChildLayoutDelegate {
static const String title = 'title';
static const String info = 'info';
static const String seller = 'seller';
@override
void performLayout(Size size) {
final Size titleSize = layoutChild(title, BoxConstraints(maxWidth: size.width));
positionChild(title, Offset(0, 0));
layoutChild(info, BoxConstraints(maxWidth: size.width));
positionChild(info, Offset(0, titleSize.height));
final Size sellerSize = layoutChild(seller, BoxConstraints());
positionChild(seller, Offset(size.width - sellerSize.width - 20, titleSize.height - sellerSize.height / 2));
}
@override
bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) {
return true;
}
}
Actual result:
The height of CustomMultiChildLayout
always equals to BoxConstraint.maxHeight, it cannot adjust its height according to its children.
Please refer to this image:
There is a useless empty space on the bottom of this widget.
Expected result:
Have its height adapted to its children, like other widgets.
flutter flutter-layout
flutter flutter-layout
edited Jan 2 at 6:47
Ahmed
42126
42126
asked Jan 2 at 3:29
jxw1102jxw1102
134
134
the size of the parent cannot depend on the sizes of the children. docs.flutter.io/flutter/widgets/…
– Ahmed
Jan 2 at 3:50
I think it's lot easier to achieve what you are trying to do with just Rows and Culomns.
– dshukertjr
Jan 2 at 4:06
add a comment |
the size of the parent cannot depend on the sizes of the children. docs.flutter.io/flutter/widgets/…
– Ahmed
Jan 2 at 3:50
I think it's lot easier to achieve what you are trying to do with just Rows and Culomns.
– dshukertjr
Jan 2 at 4:06
the size of the parent cannot depend on the sizes of the children. docs.flutter.io/flutter/widgets/…
– Ahmed
Jan 2 at 3:50
the size of the parent cannot depend on the sizes of the children. docs.flutter.io/flutter/widgets/…
– Ahmed
Jan 2 at 3:50
I think it's lot easier to achieve what you are trying to do with just Rows and Culomns.
– dshukertjr
Jan 2 at 4:06
I think it's lot easier to achieve what you are trying to do with just Rows and Culomns.
– dshukertjr
Jan 2 at 4:06
add a comment |
2 Answers
2
active
oldest
votes
Inspired by the implementation of Column
and Stack
, I created a custom layout to do this job. https://gist.github.com/jxw1102/a9b58a78a80c8e2f54233b418429fa50
add a comment |
You can use SingleChildScrollView
as parent to get the dynamic height of parent as per the number of child widgets.
This doesn't work.flutter: The following assertion was thrown during performLayout():
flutter: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
– jxw1102
Jan 2 at 7:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000912%2fhow-to-have-dynamic-height-in-custommultichildlayout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Inspired by the implementation of Column
and Stack
, I created a custom layout to do this job. https://gist.github.com/jxw1102/a9b58a78a80c8e2f54233b418429fa50
add a comment |
Inspired by the implementation of Column
and Stack
, I created a custom layout to do this job. https://gist.github.com/jxw1102/a9b58a78a80c8e2f54233b418429fa50
add a comment |
Inspired by the implementation of Column
and Stack
, I created a custom layout to do this job. https://gist.github.com/jxw1102/a9b58a78a80c8e2f54233b418429fa50
Inspired by the implementation of Column
and Stack
, I created a custom layout to do this job. https://gist.github.com/jxw1102/a9b58a78a80c8e2f54233b418429fa50
answered Jan 8 at 2:12
jxw1102jxw1102
134
134
add a comment |
add a comment |
You can use SingleChildScrollView
as parent to get the dynamic height of parent as per the number of child widgets.
This doesn't work.flutter: The following assertion was thrown during performLayout():
flutter: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
– jxw1102
Jan 2 at 7:07
add a comment |
You can use SingleChildScrollView
as parent to get the dynamic height of parent as per the number of child widgets.
This doesn't work.flutter: The following assertion was thrown during performLayout():
flutter: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
– jxw1102
Jan 2 at 7:07
add a comment |
You can use SingleChildScrollView
as parent to get the dynamic height of parent as per the number of child widgets.
You can use SingleChildScrollView
as parent to get the dynamic height of parent as per the number of child widgets.
answered Jan 2 at 4:53
Insane DeveloperInsane Developer
439410
439410
This doesn't work.flutter: The following assertion was thrown during performLayout():
flutter: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
– jxw1102
Jan 2 at 7:07
add a comment |
This doesn't work.flutter: The following assertion was thrown during performLayout():
flutter: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
– jxw1102
Jan 2 at 7:07
This doesn't work.
flutter: The following assertion was thrown during performLayout():
flutter: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
– jxw1102
Jan 2 at 7:07
This doesn't work.
flutter: The following assertion was thrown during performLayout():
flutter: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
– jxw1102
Jan 2 at 7:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000912%2fhow-to-have-dynamic-height-in-custommultichildlayout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
the size of the parent cannot depend on the sizes of the children. docs.flutter.io/flutter/widgets/…
– Ahmed
Jan 2 at 3:50
I think it's lot easier to achieve what you are trying to do with just Rows and Culomns.
– dshukertjr
Jan 2 at 4:06