import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:qpay/screens/pay/pay_controller.dart'; import 'package:qpay/screens/home/home_controller.dart'; part 'transaction_controller.freezed.dart'; part 'transaction_controller.g.dart'; class TransactionModel { late Map confirmationData; late PaymentProcessor selectedPaymentProcessor; late FormData repeatFormData; BillProduct? selectedProduct; BillProvider? selectedProvider; Map? receiptData; FormData formData = FormData( type: '', billClientId: '', debitRef: '', debitCurrency: '', amount: '', debitPhone: '', debitAccount: '', creditAccount: '', creditPhone: '', creditName: '', creditEmail: '', billName: '', errorMessage: '', status: 'PENDING', paymentProcessorLabel: '', charge: '', gatewayCharge: '', tax: '', totalAmount: '', paymentProcessorName: '', paymentProcessorImage: '', providerImage: '', userId: '', providerLabel: '', ); String? errorMessage; } @freezed abstract class FormData with _$FormData { const factory FormData({ String? id, required String type, // CONFIRM, REQUEST, REVERSE required String billClientId, required String debitRef, required String debitCurrency, required String amount, required String creditAccount, required String? creditPhone, required String? creditName, required String? creditEmail, required String billName, required String? errorMessage, required String status, required String paymentProcessorLabel, required String paymentProcessorName, required String paymentProcessorImage, required String providerImage, required String providerLabel, required String userId, String? debitPhone, String? debitAccount, String? productUid, String? trace, String? authType, String? charge, String? gatewayCharge, String? tax, String? totalAmount, }) = _FormData; factory FormData.fromJson(Map json) => _$FormDataFromJson(json); } class TransactionController extends ChangeNotifier { TransactionModel model = TransactionModel(); updateSelectedProvider(BillProvider provider) { model.selectedProvider = provider; notifyListeners(); } updateSelectedProduct(BillProduct product) { model.selectedProduct = product; notifyListeners(); } updateSelectedPaymentProcessor(PaymentProcessor processor) { model.selectedPaymentProcessor = processor; notifyListeners(); } updateConfirmationData(Map data) { model.confirmationData = data; notifyListeners(); } updateReceiptData(Map data) { model.receiptData = data; notifyListeners(); } updateRepeatFormData(FormData data) { model.repeatFormData = data; notifyListeners(); } clearFormData() { model.formData = FormData( id: null, type: '', billClientId: '', debitRef: '', debitCurrency: '', amount: '', debitPhone: '', debitAccount: '', creditAccount: '', creditPhone: '', creditName: '', creditEmail: '', billName: '', errorMessage: '', status: 'PENDING', paymentProcessorLabel: '', charge: '', gatewayCharge: '', tax: '', totalAmount: '', paymentProcessorName: '', paymentProcessorImage: '', providerImage: '', userId: '', providerLabel: '', ); notifyListeners(); } }