I'm using bloc for getting the data entered to a textField and store it in a variable. I keep getting the error: "type '_ControllerSubscription' is not a subtype of type 'Stream'" after adding listener to the stream.
UI:
/****/
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
var bloc = Bloc();
return Container(
color: Colors.white,
child: Column(children: <Widget>[
SizedBox(height: size.height *.2 ,),
StreamBuilder( stream: bloc.textStream,
builder: (context, snapshot ){
return Container(
width: size.height * .5,
height: size.height *.2,
child: TextField(
onChanged: bloc.changeText,
textAlign: TextAlign.right,
decoration: InputDecoration(
hintStyle: TextStyle(
fontSize: 14,
color: Colors.black,
),),
/****
*****/
Bloc:
import 'dart:async';
class Bloc {
var _text='';
final _textFieldController = StreamController<String>();
get textStream => _textFieldController.stream
.listen( (value){_text = value;});
Function(String) get changeText => _textFieldController.sink.add;
void dispose() {
_textFieldController.close();
}
}
Try replacing
get textStream => _textFieldController.stream
.listen( (value){_text = value;});
with
get textStream => _textFieldController.stream;