在最新的 bloc 包中使用 stream.listen 是什么意思
What does it mean to use stream.listen in latest bloc package
我正在使用 bloc: ^7.0.0,它是当前最新的 bloc 包,它现在表示 listen 方法现已弃用。相反,我应该使用 stream.listen。但我不明白如何使用 stream.listen。请帮忙解释一下。谢谢!
下面是我的代码:
signInBloc.l̶i̶s̶t̶e̶n̶((state) {
if (state is CheckIfSignedInEventCompletedState) {
if (state.isSignedIn) {
print('logged in');
} else {
print('not logged in');
}
}
class SignInBloc extends Bloc<SignInEvent, SignInState> {
@override
Stream<SignInState> mapEventToState(
SignInEvent event,
) async* {
if (event is CheckIfSignedInEvent) {
yield* mapCheckIfSignedInEventToState();
}
}
Stream<SignInState> mapCheckIfSignedInEventToState() async* {
try {
bool isSignedIn = await authenticationRepository.checkIfSignedIn();
if (isSignedIn != null) {
if (isSignedIn) {
yield CheckIfSignedInEventCompletedState(true);
} else {
yield CheckIfSignedInEventCompletedState(false);
}
} else {
yield CheckIfSignedInEventFailedState();
}
} catch (e) {
print(e);
yield CheckIfSignedInEventFailedState();
}
}
}
signInBloc.l̶i̶s̶t̶e̶n̶((state) {
简单地变成:
signInBloc.stream.listen((state) {
在此处查看从 6.1.x 到 7.0.0 的 bloc 迁移指南:https://bloclibrary.dev/#/migration?id=packagebloc
我正在使用 bloc: ^7.0.0,它是当前最新的 bloc 包,它现在表示 listen 方法现已弃用。相反,我应该使用 stream.listen。但我不明白如何使用 stream.listen。请帮忙解释一下。谢谢!
下面是我的代码:
signInBloc.l̶i̶s̶t̶e̶n̶((state) {
if (state is CheckIfSignedInEventCompletedState) {
if (state.isSignedIn) {
print('logged in');
} else {
print('not logged in');
}
}
class SignInBloc extends Bloc<SignInEvent, SignInState> {
@override
Stream<SignInState> mapEventToState(
SignInEvent event,
) async* {
if (event is CheckIfSignedInEvent) {
yield* mapCheckIfSignedInEventToState();
}
}
Stream<SignInState> mapCheckIfSignedInEventToState() async* {
try {
bool isSignedIn = await authenticationRepository.checkIfSignedIn();
if (isSignedIn != null) {
if (isSignedIn) {
yield CheckIfSignedInEventCompletedState(true);
} else {
yield CheckIfSignedInEventCompletedState(false);
}
} else {
yield CheckIfSignedInEventFailedState();
}
} catch (e) {
print(e);
yield CheckIfSignedInEventFailedState();
}
}
}
signInBloc.l̶i̶s̶t̶e̶n̶((state) {
简单地变成:
signInBloc.stream.listen((state) {
在此处查看从 6.1.x 到 7.0.0 的 bloc 迁移指南:https://bloclibrary.dev/#/migration?id=packagebloc