flutter streams bloc 显示句柄可见状态
flutter streams bloc to show handle visible state
我有一个小部件 isLive
,它会根据 bloc.However 每次我 运行 我获得的应用程序返回的值更改状态
The getter 'progressStateStream' was called on 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 添加到 init 状态,在 init 状态初始化我的 bloc 来修复它
_bloc = RBloc();
_bloc.progressStateStream;
我有一个小部件 isLive
,它会根据 bloc.However 每次我 运行 我获得的应用程序返回的值更改状态
The getter 'progressStateStream' was called on 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 添加到 init 状态,在 init 状态初始化我的 bloc 来修复它
_bloc = RBloc();
_bloc.progressStateStream;