[我有一个小部件isLive
,它会根据块返回的值来更改状态。但是,每次我运行该应用程序时,我都会得到
getter'progressStateStream'被调用为null
我尝试遵循此answer
Widget isLive() {
return Container(
child: StreamBuilder<bool>(
stream: _bloc.progressStateStream,
builder: (context, snapshot) {
return Visibility(
maintainState: true,
visible: snapshot.data ?? false,
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
color: Colors.pink[50],
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text("yaay i'm visible"),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text(
"hide"
),
color: Colors.white,
onPressed: () {
_bloc.changeProgressState(state: false);
},
)
],
),
),
),
);
},
));
}
这是我的团体
//this Subject allows sending data, error and done events to the listener
final PublishSubject<bool> _progressStateSubject = new PublishSubject();
//the listener are streaming on changes
Observable<bool> get progressStateStream => _progressStateSubject.stream;
//to change your progress state
void changeProgressState({bool state}) => _progressStateSubject.sink.add(state);
此外,如果我想用水合集团保存国家,我将如何处理
_bloc = RBloc();
_bloc.progressStateStream;