类型“_ControllerSubscription<String>”不是类型 'Stream<dynamic>' 的子类型
type '_ControllerSubscription<String>' is not a subtype of type 'Stream<dynamic>'
我正在使用 bloc 获取输入文本字段的数据并将其存储在变量中。我不断收到错误消息:"type '_ControllerSubscription' is not a subtype of type '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,
),),
/****
*****/
集团:
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();
}
}
尝试替换
get textStream => _textFieldController.stream
.listen( (value){_text = value;});
和
get textStream => _textFieldController.stream;
我正在使用 bloc 获取输入文本字段的数据并将其存储在变量中。我不断收到错误消息:"type '_ControllerSubscription' is not a subtype of type '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,
),),
/****
*****/
集团:
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();
}
}
尝试替换
get textStream => _textFieldController.stream
.listen( (value){_text = value;});
和
get textStream => _textFieldController.stream;