我正在从数据库中加载一些数据(用户之前保存的数据,用于编辑)。我曾经StreamBuilder
设置数据。
我有用于显示数据的表单,我使用它TextFormField
是因为我需要使用验证。我连接TextEditingController
到TextFormField
然后我连接StreamBuilder
到TextEditingController
但是当我在加载后编辑数据时它给了我异常。
这是我的表单代码。
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(),
);
}
});
}
我得到了这个例外
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