Added qr bloc
This commit is contained in:
parent
bb4cbcabe7
commit
89fdcce613
6 changed files with 56 additions and 0 deletions
14
lib/blocs/qr/functions/bloc_getqr.dart
Normal file
14
lib/blocs/qr/functions/bloc_getqr.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:ocbo_esign_mobile/blocs/qr/qr_bloc.dart';
|
||||||
|
import 'package:ocbo_esign_mobile/blocs/qr/qr_event.dart';
|
||||||
|
|
||||||
|
Future<String> blocGetQr(BuildContext context) async {
|
||||||
|
try {
|
||||||
|
final qrBloc = context.read<QrBloc>();
|
||||||
|
qrBloc.add(QrGetValue());
|
||||||
|
return qrBloc.state.value;
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
14
lib/blocs/qr/functions/bloc_setqr.dart
Normal file
14
lib/blocs/qr/functions/bloc_setqr.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:ocbo_esign_mobile/blocs/qr/qr_bloc.dart';
|
||||||
|
import 'package:ocbo_esign_mobile/blocs/qr/qr_event.dart';
|
||||||
|
|
||||||
|
Future<bool> blocSetQr(BuildContext context, String value) async {
|
||||||
|
try {
|
||||||
|
final qrBloc = context.read<QrBloc>();
|
||||||
|
qrBloc.add(QrSetValue(value));
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
lib/blocs/qr/qr_bloc.dart
Normal file
14
lib/blocs/qr/qr_bloc.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:ocbo_esign_mobile/blocs/qr/qr_event.dart';
|
||||||
|
import 'package:ocbo_esign_mobile/blocs/qr/qr_state.dart';
|
||||||
|
|
||||||
|
class QrBloc extends Bloc<QrEvent, QrState> {
|
||||||
|
QrBloc() : super(QrState('')) {
|
||||||
|
on<QrSetValue>((event, emit) {
|
||||||
|
emit(QrState(event.value));
|
||||||
|
});
|
||||||
|
on<QrGetValue>((event, emit) {
|
||||||
|
emit(state);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
8
lib/blocs/qr/qr_event.dart
Normal file
8
lib/blocs/qr/qr_event.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
abstract class QrEvent {}
|
||||||
|
|
||||||
|
class QrSetValue extends QrEvent {
|
||||||
|
final String value;
|
||||||
|
QrSetValue(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class QrGetValue extends QrEvent {}
|
||||||
5
lib/blocs/qr/qr_state.dart
Normal file
5
lib/blocs/qr/qr_state.dart
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class QrState {
|
||||||
|
final String value;
|
||||||
|
|
||||||
|
QrState(this.value);
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:developer';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:dio_smart_retry/dio_smart_retry.dart';
|
import 'package:dio_smart_retry/dio_smart_retry.dart';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue