updating sequence of flows
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
||||
import 'package:qpay/screens/transaction_controller.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
@@ -17,7 +16,6 @@ class IntegrationScreen extends StatefulWidget {
|
||||
class _IntegrationScreenState extends State<IntegrationScreen> {
|
||||
late IntegrationController controller;
|
||||
late TransactionController transactionController;
|
||||
late GatewayController gatewayController;
|
||||
|
||||
bool integrating = false;
|
||||
|
||||
@@ -25,27 +23,12 @@ class _IntegrationScreenState extends State<IntegrationScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = IntegrationController(context);
|
||||
gatewayController = GatewayController(context);
|
||||
transactionController = Provider.of<TransactionController>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() async {
|
||||
super.didChangeDependencies();
|
||||
|
||||
if(integrating) return;
|
||||
|
||||
String status = Provider.of<TransactionController>(context).model.paymentStatus;
|
||||
if(status == 'SUCCESS') {
|
||||
setState(() {
|
||||
integrating = true;
|
||||
});
|
||||
await controller.doIntegration();
|
||||
}
|
||||
controller.doIntegration();
|
||||
}
|
||||
|
||||
void _showErrorSnackBar(String? message) {
|
||||
@@ -74,91 +57,64 @@ class _IntegrationScreenState extends State<IntegrationScreen> {
|
||||
title: const Text('Completing your transaction'),
|
||||
),
|
||||
body: ListenableBuilder(
|
||||
listenable: gatewayController,
|
||||
listenable: controller,
|
||||
builder: (context, child) {
|
||||
return ListenableBuilder(
|
||||
listenable: controller,
|
||||
builder: (context, child) {
|
||||
if (controller.model.status == 'SUCCESS') {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/receipt');
|
||||
});
|
||||
}
|
||||
if (controller.model.status == 'SUCCESS') {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/receipt');
|
||||
});
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.all(50),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
return Container(
|
||||
padding: EdgeInsets.all(50),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(height: 75),
|
||||
|
||||
Column(
|
||||
children: [
|
||||
SizedBox(height: 75),
|
||||
|
||||
if(transactionController.model.paymentStatus != 'SUCCESS')
|
||||
Text(
|
||||
'We\'ve successfully collected your funds. We are now '
|
||||
'updating your billing account. This won\'t take long',
|
||||
style: TextStyle(fontSize: 20),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Image.asset('assets/peak-animation.gif', width: 150),
|
||||
SizedBox(
|
||||
width: 50,
|
||||
child: LinearProgressIndicator(),
|
||||
),
|
||||
SizedBox(height: 50),
|
||||
if(controller.model.status == 'FAILED')
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
'We failed to check your payment status',
|
||||
'We failed to update your billing account',
|
||||
style: TextStyle(fontSize: 20),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: 50,),
|
||||
SizedBox(height: 20,),
|
||||
Skeletonizer(
|
||||
enabled: gatewayController.model.isLoading,
|
||||
enabled: controller.model.isLoading,
|
||||
child: OutlinedButton(
|
||||
child: Text('Check latest status'),
|
||||
child: Text('Retry'),
|
||||
onPressed: () {
|
||||
gatewayController.poll(transactionController.model.receiptData?['id']);
|
||||
controller.doIntegration();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
if(transactionController.model.paymentStatus == 'SUCCESS')
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
'We\'ve successfully collected your funds. We are now '
|
||||
'updating your billing account. This won\'t take long',
|
||||
style: TextStyle(fontSize: 20),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Image.asset('assets/peak-animation.gif', width: 150),
|
||||
SizedBox(
|
||||
width: 50,
|
||||
child: LinearProgressIndicator(),
|
||||
),
|
||||
SizedBox(height: 50),
|
||||
if(controller.model.status == 'FAILED')
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
'We failed to update your billing account',
|
||||
style: TextStyle(fontSize: 20),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: 20,),
|
||||
Skeletonizer(
|
||||
enabled: controller.model.isLoading,
|
||||
child: OutlinedButton(
|
||||
child: Text('Retry'),
|
||||
onPressed: () {
|
||||
controller.doIntegration();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user