我在StreamBuilder
中有一个侦听BehaviorSubject
流的BehaviorSubject
。当快照出现错误时,errorText
将显示它。
问题是当TextField
从可见区域滚动并在StreamBuilder
重新构建中回滚时,错误文本就消失了,因为这次snapshot.hasError
是假的。
如何维护错误?
发布于 2019-04-10 21:09:48
您可能希望将错误存储在String
变量的StatefulWidget
中。
一旦您准备好清除错误(f.ex )。用户按一个清除按钮)简单地将这个变量设置为null。
String errorMsg;
StreamBuilder(
stream: myStream,
builder: (BuildContext context, snapshot) {
if (snapshot.hasError) {
errorMsg = snapshot.error.toString();
}
if (errorMsg != null) {
return Text(errorMsg);
}
return new Text(
snapshot.data.toString(),
);
},
)
https://stackoverflow.com/questions/55624858
复制相似问题