![](/img/trans.png)
[英]Flutter Layout - BoxConstraints: Container won't shrink below maxWidth
[英]Flutter BoxConstraints maxWidth in CustomScrollView not working
我正在使用CustomScrollView
並試圖通過使用BoxConstraints
來限制其子項的大小,但它們被簡單地忽略了。 我的文本擴展到屏幕的寬度,我不明白為什么。
這是我的代碼:
SliverToBoxAdapter(
child: ConstrainedBox(
constraints: maxWidthConstraint,
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.project.description,
),
],
),
),
),
),
我在這里錯過了什么? 如果您需要更多信息,請告訴我!
父級強制它為全寬,因此您可以使用UnconstrainedBox
或Align
或Center
小部件將其包裝起來以擺脫這種行為。
SliverToBoxAdapter(
child: UnconstrainedBox( // this should allow it to have its own constraints
child: ConstrainedBox(
constraints: maxWidthConstraint,
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.project.description,
),
],
),
),
),
),
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.