passo_mobile_app/lib/bloc/docsms/docsms_bloc.dart

29 lines
791 B
Dart
Raw Normal View History

2023-04-25 07:50:36 +00:00
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/sevices/docsms/docsms_service.dart';
import '../../model/docsms/document.dart';
part 'docsms_event.dart';
part 'docsms_state.dart';
class DocsmsBloc extends Bloc<DocsmsEvent, DocsmsState> {
DocsmsBloc() : super(DocsmsInitial()) {
Document? document;
on<LoadDocument>((event, emit)async {
emit(DocSmsLoadingState());
try {
document = await AutoReceiveDocumentServices.instance.getDocument(event.documentId);
if(document != null){
emit(DocumentLoaded(document: document!));
}else{
emit(const DocSmsErrorState(message: "Invalid Qr code"));
}
} catch (e) {
emit(DocSmsErrorState(message: e.toString()));
}
});
}
}