【问题标题】:Exception caught by widgets library. Incorrect use of ParentDataWidget in Flutter小部件库捕获的异常。 Flutter 中不正确使用 ParentDataWidget
【发布时间】:2021-09-27 02:29:30
【问题描述】:

我收到此错误。我读到这个错误的问题是Expanded 以及将它与columnrowflex 一起使用的解决方案。但是在我的代码中,我是这样使用的,所以应该没有错误。请帮帮我。

我的代码:

  List<DataColumn> initHeader() {
    List<DataColumn> header = [];
    for (var i = 0; i < widget.headerList.length; i++) {
      header.add(new DataColumn(
          label: Flexible(
        child: Text(
          widget.headerList[i].name,
        ),
      )));
    }
    return header;
  }

错误:

【问题讨论】:

  • 你能分享tableReport()小部件吗,我相信它来自那里
  • 你能显示错误吗?
  • 还有关于HeaderTable
  • 你在为这个HeaderTable 使用任何 pub 包吗?你能添加一个你试图归档的文件吗
  • 我在那儿找不到HeaderTable,你能重新检查一下问题吗

标签: flutter dart widget expand


【解决方案1】:

让我们使用这段代码,它会解决你的问题

 Widget build(BuildContext context) {
        return Scaffold(
         body: Form(
            key: _formKey,
            child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
            TextFormField(
           //ontroller: skuController,
            textInputAction: TextInputAction.done,
            decoration: InputDecoration(
          //labelText: AppLocalizations.instance.text('Scan'),
        suffixIcon: IconButton(
        onPressed: () {},
        icon: Icon(Icons.search),
        ),
        ),
      ),
     //ableReport(this.getProduct()),
      Row(
      children: <Widget>[
      Expanded(
      child: Padding(
      padding: const EdgeInsets.only(top: 25),
      child: ElevatedButton(
      onPressed: () {},
      child: Text('Submit'),
      ),
      )),
      Expanded(
      child: Padding(
      padding: const EdgeInsets.only(top: 25),
      child: ElevatedButton(
      onPressed: () {},
      child: Text(
      'Check items',
      textAlign: TextAlign.center,
      ),
      ),
      )),
      ],
      ),
      ],
      ),
      ));
    }
    }

【讨论】:

    【解决方案2】:

    我将Flexible 更改为Container,它运行良好且没有错误。

    之前:

      List<DataColumn> initHeader() {
        List<DataColumn> header = [];
        for (var i = 0; i < widget.headerList.length; i++) {
          header.add(new DataColumn(
              label: Flexible(
            child: Text(
              widget.headerList[i].name,
            ),
          )));
        }
        return header;
      }
    

    之后:

      List<DataColumn> initHeader() {
        List<DataColumn> header = [];
        for (var i = 0; i < widget.headerList.length; i++) {
          header.add(new DataColumn(
              label: Container(
            child: Text(
              widget.headerList[i].name,
            ),
          )));
        }
        return header;
      }
    

    【讨论】:

      猜你喜欢
      • 2022-11-30
      • 2022-06-12
      • 1970-01-01
      • 2021-10-04
      • 2019-06-13
      • 1970-01-01
      • 2020-08-18
      • 2023-03-29
      相关资源
      最近更新 更多