I have a text field wrapped in a StreamBuilder and tied to a stream, the stream runs through a validator when data is added to the sink. There's a button which adds the text field value to the sink and any snapshot error is displayed on the InputDecoration.
The text field is inside a stateful widget which is a component of a parent stateful widget. The bloc is initialized outside of the Widget builder.
What I'm trying to do is reset the stream so that the snapshot error is no longer there when the child widget animates in and out of view. Currently, the error persists after the child widget rebuilds. Any idea on how to achieve this?
class Parent extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return ParentState();
}
}
class ParentState extends State<Parent> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return Container(
child: Stack(
children: <Widget>[
child(),
// other forms
],
)
);
}
}
class Child extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return ChildState();
}
}
class ChildState extends State<Child> {
Bloc bloc;
@override
void initState() {
super.initState();
bloc = Bloc();
}
@override
Widget build(BuildContext context) {
return BlocProvider(
bloc: appBloc,
child: Container(
child: StreamBuilder(
stream: bloc.input,
builder: (context, snapshot) {
return TextFormField(
decoration: InputDecoration(
errorText: snapshot.error,
),
);
}
),
),
);
}
}