padmanto
2 years ago
11 changed files with 274 additions and 37 deletions
@ -0,0 +1,79 @@
|
||||
import 'package:dio/dio.dart'; |
||||
import 'package:equatable/equatable.dart'; |
||||
import 'package:flutter_riverpod/flutter_riverpod.dart'; |
||||
|
||||
import '../../provider/dio_provider.dart'; |
||||
import '../../provider/local_auth_provider.dart'; |
||||
import '../../repository/base_repository.dart'; |
||||
import '../../repository/mitra_repository.dart'; |
||||
|
||||
final mitraAddProvider = StateNotifierProvider<MitraAddNotifier, MitraAddState>( |
||||
(ref) => MitraAddNotifier(ref: ref), |
||||
); |
||||
|
||||
class MitraAddNotifier extends StateNotifier<MitraAddState> { |
||||
final Ref ref; |
||||
CancelToken? cancelToken; |
||||
MitraAddNotifier({ |
||||
required this.ref, |
||||
}) : super(MitraAddStateInit()); |
||||
|
||||
void reset() { |
||||
state = MitraAddStateInit(); |
||||
} |
||||
|
||||
void add({ |
||||
required String companyID, |
||||
required List<String> mouID, |
||||
required String doctorID, |
||||
required String doctorAddressID, |
||||
required String login, |
||||
}) async { |
||||
try { |
||||
state = MitraAddStateLoading(); |
||||
final dio = ref.read(dioProvider); |
||||
final localAuth = ref.read(localAuthProvider); |
||||
if (localAuth?.token == null) { |
||||
throw BaseRepositoryException(message: "Invalid Token"); |
||||
} |
||||
await MitraRepository(dio: dio).add( |
||||
token: localAuth!.token!, |
||||
mouID: mouID, |
||||
companyID: companyID, |
||||
doctorID: doctorID, |
||||
doctorAddressID: doctorAddressID, |
||||
login: login, |
||||
); |
||||
state = MitraAddStateDone(); |
||||
} catch (e) { |
||||
if (e is BaseRepositoryException) { |
||||
state = MitraAddStateError(message: e.message); |
||||
} else { |
||||
state = MitraAddStateError(message: "Unknown Error "); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
abstract class MitraAddState extends Equatable { |
||||
final DateTime date; |
||||
MitraAddState() : date = DateTime.now(); |
||||
@override |
||||
List<Object?> get props => throw [date]; |
||||
} |
||||
|
||||
class MitraAddStateInit extends MitraAddState {} |
||||
|
||||
class MitraAddStateLoading extends MitraAddState {} |
||||
|
||||
class MitraAddStateError extends MitraAddState { |
||||
final String message; |
||||
|
||||
MitraAddStateError({ |
||||
required this.message, |
||||
}); |
||||
} |
||||
|
||||
class MitraAddStateDone extends MitraAddState { |
||||
MitraAddStateDone(); |
||||
} |
@ -1,5 +1,8 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart'; |
||||
|
||||
import '../../model/ac_company_response_model.dart'; |
||||
import '../../model/ac_mou_response_model.dart'; |
||||
|
||||
final selectdAcCompanyProvider = StateProvider<AcCompanyModel?>((ref) => null); |
||||
final selectedAcCompanyProvider = StateProvider<AcCompanyModel?>((ref) => null); |
||||
final selectedMouProvider = |
||||
StateProvider<List<AcMouResponseModel>>((ref) => List.empty()); |
||||
|
Loading…
Reference in new issue