valueStream method
Use this function to stream a text field value using the unique id you supplied earlier!
{@tool snippet}
StreamBuilder<String>(
stream: _formController.valueStream("id1"),
builder: (context, snapshot) {
return Text("Stream of id1: ${snapshot.data}");
},
),
{@end-tool}
Implementation
Stream<String> valueStream(String id) {
late Stream<String> stream;
if (_textControllers.containsKey(id) && _textControllers[id] != null) {
_streamControllers.addEntries([MapEntry(id, StreamController())]);
// ignore: close_sinks
StreamController<String> c = _streamControllers[id]!;
stream = c.stream;
_textControllers[id]!.addListener(() {
c.add(_textControllers[id]!.text);
});
} else {
throw Exception(
"No controllers found with the provided id, Did you create a controller with this id? Did you wait for the controller to initializ?");
}
return stream;
}