簡體   English   中英

Flutter:Row 在 Wrap 內跨行

[英]Flutter: Row is stepping a line inside a Wrap

假設我們有:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Wrap(
      children: [
        Row(
          children: [
            Text('a'),
          ],
        ),
        Row(
          children: [
            Text('b'),
          ],
        ),
      ],
    );
  }
}

其輸出將是: 這個的輸出將是

注意每個Row是如何占據整條線的

我該如何解決這個問題並使它們並排?

你應該用FittedBox包裹你的Row ,這將使它們只消耗它們需要的空間,所以你的代碼應該是這樣的:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Wrap(
      children: [
        FittedBox(
          child: Row(
            children: [
              Text('a'),
            ],
          ),
        ),
        FittedBox(
          child: Row(
            children: [
              Text('b'),
            ],
          ),
        ),
      ],
    );
  }
}

你的輸出將是這樣的: 你的輸出將是這樣的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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