Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何使用StreamBuilder将数据设置为TextEditingController?_Flutter_Dart_Stream Builder - Fatal编程技术网

Flutter 如何使用StreamBuilder将数据设置为TextEditingController?

Flutter 如何使用StreamBuilder将数据设置为TextEditingController?,flutter,dart,stream-builder,Flutter,Dart,Stream Builder,我正在从数据库加载一些数据(用户以前保存的数据,用于编辑)。我使用了StreamBuilder来设置数据。 我有一个表单,用来显示数据,我使用TextFormField,因为我需要使用验证。 我已将TextEditingController连接到TextFormField 然后我将StreamBuilder连接到textededitingcontroller 但当我在加载后编辑数据时,它会给我异常 这是我的表格代码 Widget _formUI() { return StreamBuil

我正在从数据库加载一些数据(用户以前保存的数据,用于编辑)。我使用了
StreamBuilder
来设置数据。
我有一个表单,用来显示数据,我使用
TextFormField
,因为我需要使用验证。 我已将
TextEditingController
连接到
TextFormField
然后我将
StreamBuilder
连接到
textededitingcontroller
但当我在加载后编辑数据时,它会给我异常

这是我的表格代码

Widget _formUI() {
    return StreamBuilder<ConcreteEstimationForm>(
        stream: _bloc.inputObservable(),
        builder: (context, AsyncSnapshot<ConcreteEstimationForm> snapshot) {
          if (snapshot.hasData) {
    ConcreteEstimationForm form = snapshot.data;
    
    _descriptionController.value = _descriptionController.value.copyWith(text: form.description) ;
    _lengthController.text =
        form.length == 0 ? "" : form.length.toString();
    _widthController.text =
        form.width == 0 ? "" : form.width.toString();
    _thickController.text =
        form.thick == 0 ? "" : form.thick.toString();

    _selectedRatio = ratioArr.indexOf(form.mixRatio);

    return Column(
      children: <Widget>[
        TextFormField(
          decoration: const InputDecoration(labelText: "Description"),
          keyboardType: TextInputType.text,
          validator: _descriptionValidator,
          controller: _descriptionController,
        ),
        Row(
          children: <Widget>[
            Expanded(
              child: TextFormField(
                decoration: const InputDecoration(labelText: "Concrete Length"),
                keyboardType: TextInputType.number,
                validator: _lengthValidator,
                controller: _lengthController,
              ),
            ),
            Expanded(
                child: Text(
              'm',
              textAlign: TextAlign.center,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(fontWeight: FontWeight.bold),
            ))
          ],
        ),
        Row(
          children: <Widget>[
            Expanded(
              child: TextFormField(
                decoration: const InputDecoration(labelText: "Concrete Width"),
                keyboardType: TextInputType.number,
                validator: _widthValidator,
                controller: _widthController,
              ),
            ),
            Expanded(
              child: Text(
                'm',
                textAlign: TextAlign.center,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
            )
          ],
        ),
        Row(
          children: <Widget>[
            Expanded(
              child: TextFormField(
                decoration: const InputDecoration(labelText: "Concrete Thick"),
                keyboardType: TextInputType.number,
                validator: _thickValidator,
                controller: _thickController,
              ),
            ),
            Expanded(
              child: Text(
                'm',
                textAlign: TextAlign.center,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
            )
          ],
        )
      ],
    );

      } else {
        return new Center(
          child: new CircularProgressIndicator(),
        );
      }

    });
  }

能否确保
\u bloc.inputObservable()
不为空?是。当我在函数中添加普通
Text()
时,在
ConcreteEstimationForm=snapshot.data下
和add
form.description
它在Text()中显示描述有吗?
I/flutter ( 2626): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ 
I/flutter ( 2626): The following assertion was thrown building Builder(dirty): I/flutter ( 2626): 'package:flutter/src/widgets/basic.dart': Failed assertion: line 6220 pos 15: 'builder != null': is I/flutter ( 2626): not true. I/flutter ( 2626): I/flutter ( 2626): Either the assertion indicates an error in the framework itself, or we should provide substantially I/flutter ( 2626): more information in this error message to help you determine and fix the underlying cause. I/flutter ( 2626): In either case, please report this assertion by filing a bug on GitHub: I/flutter ( 2626):   https://github.com/flutter/flutter/issues/new?template=BUG.md