簡體   English   中英

Flutter CustomScrollView 中的 BoxConstraints 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,
            ),
          ],
        ),
      ),
    ),
  ),

我在這里錯過了什么? 如果您需要更多信息,請告訴我!

父級強制它為全寬,因此您可以使用UnconstrainedBoxAlignCenter小部件將其包裝起來以擺脫這種行為。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM