在Flutter中的列内插入一行

问题描述 投票:0回答:1

我的UI屏幕基本上是使用Column Widget呈现的,在这个小部件中,我插入了所有其他UI组件。其中一个恰好是一行(由2个文本字段组成)。这是Row Widget:

var phoneNumber = new Row(
  children: <Widget>[
    new Padding(
      padding: const EdgeInsets.all(20.0),
      child: countryCodePicker,
    ),
    new Padding(
      padding: const EdgeInsets.all(20.0),
      child: mobileNumber,
    ),
  ],
);

主UI屏幕是:

     return SafeArea(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
                customerName,
                emailAddress,
//                new Container(
//                  child: deliveryOptionRow,
//                ),
                mobileNumber,
                countryCodePicker,
                templateMessagesDropDown,
                templateMessageTextField,
                sendGoogleReview,
              ],
            )
    );

当我将Row添加到Column时,我看到了这个异常

     The following RenderObject was being processed when the exception was fired:
flutter:   _RenderListTile#06b03 relayoutBoundary=up11 NEEDS-LAYOUT NEEDS-PAINT
flutter:   creator: _ListTile ← MediaQuery ← Padding ← SafeArea ← Semantics ← Listener ← _GestureSemantics ←
flutter:   RawGestureDetector ← GestureDetector ← InkWell ← ListTile ← ListTileTheme ← ⋯
flutter:   parentData: offset=Offset(0.0, 0.0) (can use size)
flutter:   constraints: BoxConstraints(unconstrained)
flutter:   size: MISSING
flutter: This RenderObject had the following descendants (showing up to depth 5):
flutter:   _RenderRadio#302a4 relayoutBoundary=up12 NEEDS-PAINT
flutter:   RenderParagraph#58a45 NEEDS-LAYOUT NEEDS-PAINT

在主UI屏幕中添加行的最佳方法是什么。

flutter flutter-layout
1个回答
7
投票

这应该可以解决你的问题,

var phoneNumber = new Row(
  mainAxisSize: MainAxisSize.min,
  children: <Widget>[
    Expanded(
      child: new Padding(
        padding: const EdgeInsets.all(20.0),
        child: countryCodePicker,
      ),
    ),
    Expanded(
      child: new Padding(
        padding: const EdgeInsets.all(20.0),
        child: mobileNumber,
      ),
    ),
  ],
);

希望能帮助到你!

© www.soinside.com 2019 - 2024. All rights reserved.