我在调用方法时得到null。我什至尝试调试,但坚持使用expect(isOPDSAgent(ua)).to.be.ok;
,但不知道为什么我会得到null。调试后,我完全迷失了所缺少的东西,下面是该设备的代码和屏幕截图。也许有人可以帮助我解决零点异常
主页
getNotification()
Notification_bloc
child: BlocListener<NotificationBloc, NotificationState>(
listener: (context, state) {
},
child: BlocBuilder<NotificationBloc, NotificationState>(
builder: (context, state) {
if(state is InitialNotificationState) {
return buildLoading();
}
else if (state is NotificationLoadedState) {
return NotificationIconBuild(state.notification);
}
else if(state is NotificationErrorState) {
return buildErrorUi(state.message1);
}
},
NotificationRepository
class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
NotificationsRepositoryImp notificationsRepository;
NotificationBloc({@required this.notificationsRepository});
@override
NotificationState get initialState => InitialNotificationState();
@override
Stream<NotificationState> mapEventToState(
NotificationEvent event,
) async* {
if(event is FetchNotificationEvent){
try {
NotificationModle notification = await notificationsRepository.getNotifications();
yield NotificationLoadedState(notification: notification);
}
catch (e) {
yield NotificationErrorState(message1: e.toString());
}
}
是blocbuilder中的问题吗,因为在主页中我添加了两个blocbuilder。