【问题标题】:How to Fix this particular "Incorrect use of ParentDataWidget." Flutter Dart如何修复这个特定的“不正确使用 ParentDataWidget”。飞镖
【发布时间】:2021-07-27 06:04:17
【问题描述】:

所以我一直在寻找有关此错误的在线答案,而且他们总是建议我用 ColumnFlex 包装 Expanded ,或。但就我而言,它只是不起作用,在这里,看看我的代码

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

如果你们能帮我找到这件事的罪魁祸首,我会很高兴..谢谢!

【问题讨论】:

  • 将完整的错误消息复制粘贴到问题中。 不要将它们作为图片发布。
  • 好的,下次会做

标签: android flutter dart widget parent


【解决方案1】:

您的示例对我来说很好用.. 只需确保在具有指定高度的小部件中调用 _getActionButtons(),否则请删除 Flex 小部件。

例如这样

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

【讨论】:

    【解决方案2】:

    您有一个扩展的小部件作为容器小部件的子小部件,这在 Flutter 中是不允许的。

    扩展的小部件只能是小部件的直接子级,例如 Column、Row、...

    【讨论】:

      猜你喜欢
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 1970-01-01
      • 2021-10-04
      • 2021-02-09
      • 2020-10-10
      • 2020-11-18
      相关资源
      最近更新 更多