Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum StatusState { initial, loading, success, error }
- class BaseState<T> {
- StatusState status;
- T? data;
- dynamic message;
- BaseState({
- this.status = StatusState.initial,
- this.data,
- this.message,
- });
- BaseState<T> copyWith({
- StatusState? status,
- T? data,
- dynamic message,
- }) {
- return BaseState<T>(
- status: status ?? this.status,
- data: data ?? this.data,
- message: message ?? this.message,
- );
- }
- @override
- String toString() {
- return 'BaseState{status: $status, data: $data, message: $message}';
- }
- }
- BaseState<FareUpdateResponse> lrtFareState = BaseState<FareUpdateResponse>();
- Future<void> getPriceNew({PostBuyTicketModel? data}) async {
- lrtFareState = lrtFareState.copyWith(status: StatusState.loading);
- notifyListeners();
- try {
- final response = await EndPoint.getFareQTS(
- org: '${data?.origin}',
- des: '${data?.destination}',
- ticketNo: '${data?.ticketNo}',
- );
- if (response['code'] == '00') {
- lrtFareState = lrtFareState.copyWith(
- status: StatusState.success,
- data: FareUpdateResponse.fromJson(response),
- );
- notifyListeners();
- } else {
- lrtFareState = lrtFareState.copyWith(
- status: StatusState.error,
- message: response['message'],
- );
- }
- notifyListeners();
- } catch (e) {
- lrtFareState = lrtFareState.copyWith(
- status: StatusState.error,
- message: e.toString(),
- );
- notifyListeners();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment