fixes on onboarding flow
This commit is contained in:
75
lib/screens/integration/integration_controller.dart
Normal file
75
lib/screens/integration/integration_controller.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/screens/transaction_controller.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class IntegrationModel {
|
||||
Map<String, dynamic>? transaction;
|
||||
String status = '';
|
||||
bool isLoading = false;
|
||||
String? errorMessage;
|
||||
}
|
||||
|
||||
class IntegrationController extends ChangeNotifier {
|
||||
final IntegrationModel model = IntegrationModel();
|
||||
final Http http = Http();
|
||||
late TransactionController transactionController;
|
||||
late SharedPreferences prefs;
|
||||
|
||||
BuildContext context;
|
||||
|
||||
IntegrationController(this.context) {
|
||||
transactionController = Provider.of<TransactionController>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
}
|
||||
|
||||
void _showErrorSnackBar(String? message) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message.toString()),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.deepOrange,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Future<void> doIntegration() async {
|
||||
try {
|
||||
model.isLoading = true;
|
||||
model.status = '';
|
||||
notifyListeners();
|
||||
|
||||
dynamic workflowResponse = await http.get(
|
||||
'/public/transaction/integration/'
|
||||
'${transactionController.model.confirmationData['id']}'
|
||||
);
|
||||
logger.i(workflowResponse.toString());
|
||||
|
||||
dynamic response = workflowResponse['body'];
|
||||
|
||||
if (response['status'] == 'SUCCESS') {
|
||||
model.status = response['status'];
|
||||
transactionController.updateReceiptData(response);
|
||||
} else {
|
||||
model.status = response['status'];
|
||||
model.errorMessage = response['errorMessage'];
|
||||
_showErrorSnackBar(response['errorMessage']);
|
||||
}
|
||||
notifyListeners();
|
||||
|
||||
} catch (e) {
|
||||
model.isLoading = false;
|
||||
model.errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user