简体   繁体   English

如何修复这个特定的“不正确使用 ParentDataWidget”。 Flutter Dart

[英]How to Fix this particular "Incorrect use of ParentDataWidget." Flutter Dart

So I've been looking online answers about this error and always all of them would recommend me to wrap Expanded with Column , Flex , or Row .因此,我一直在寻找有关此错误的在线答案,并且总是所有人都建议我用ColumnFlexRow包装Expanded But in my case, it's just not working, here, take a look at my codes但就我而言,它只是不起作用,在这里,看看我的代码

Widget _getActionButtons() {
return Padding(
  padding: EdgeInsets.only(left: 25.0, right: 25.0, top: 45.0),
  child: new Row(
    mainAxisSize: MainAxisSize.max,
    mainAxisAlignment: MainAxisAlignment.start,
    children: <Widget>[
      Flex(
        mainAxisAlignment: MainAxisAlignment.start,
        direction: Axis.vertical,
        children: [
          Expanded(
            child: Padding(
              padding: EdgeInsets.only(left: 10.0),
              child: Container(
                  child: new RaisedButton(
                child: new Text("Cancel"),
                textColor: Colors.white,
                color: Colors.pink[800],
                onPressed: () {
                  setState(() {
                    _status = true;
                    FocusScope.of(context).requestFocus(new FocusNode());
                  });
                },
                shape: new RoundedRectangleBorder(
                    borderRadius: new BorderRadius.circular(20.0)),
              )),
            ),
            flex: 2,
          ),
        ],
      ),

Here's the error message这是错误消息

I would be very happy if you guys would help me find the culprit of this.. thanks!如果你们能帮我找到这件事的罪魁祸首,我会很高兴..谢谢!

You have an expanded widget as the child of a container widget and that is not permitted in Flutter.您有一个扩展的小部件作为容器小部件的子小部件,这在 Flutter 中是不允许的。

An expanded widget should only be direct child of widgets such as Column, Row, ...扩展的小部件只能是小部件的直接子级,例如 Column、Row、...

well your example works fine with me.. just make sure to call _getActionButtons() in a widget that has a specified amount of height otherwise remove the Flex widget.好吧,您的示例对我来说很好..只需确保在具有指定高度的小部件中调用_getActionButtons() ,否则请删除 Flex 小部件。

for example like this例如像这样

Container(height: 200.0,child: _getActionButtons(),) ,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM