128 lines
4.4 KiB
Dart
128 lines
4.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:qpay/models/responsive_policy.dart';
|
|
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
|
import 'package:qpay/screens/transaction_controller.dart';
|
|
import 'package:skeletonizer/skeletonizer.dart';
|
|
|
|
class PollScreen extends StatefulWidget {
|
|
const PollScreen({super.key});
|
|
|
|
@override
|
|
State<PollScreen> createState() => _PollScreenState();
|
|
}
|
|
|
|
class _PollScreenState extends State<PollScreen> {
|
|
late GatewayController controller;
|
|
late TransactionController transactionController;
|
|
|
|
bool integrating = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
controller = GatewayController(context);
|
|
transactionController = Provider.of<TransactionController>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
|
|
controller.pollTransaction(transactionController.model.confirmationData['id']);
|
|
}
|
|
|
|
void _showErrorSnackBar(String? message) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(message.toString()),
|
|
behavior: SnackBarBehavior.floating,
|
|
backgroundColor: Colors.deepOrange,
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Completing your transaction'),
|
|
),
|
|
body: ListenableBuilder(
|
|
listenable: controller,
|
|
builder: (context, child) {
|
|
if (controller.model.status == 'SUCCESS') {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.go('/integration');
|
|
});
|
|
}
|
|
|
|
return Container(
|
|
padding: EdgeInsets.all(50),
|
|
child: Center(
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
return SizedBox(
|
|
width: double.parse(constraints.maxWidth > ResponsivePolicy.md ?
|
|
ResponsivePolicy.md.toString() :
|
|
constraints.maxWidth.toString()),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
SizedBox(height: 75),
|
|
|
|
Column(
|
|
children: [
|
|
Text(
|
|
'We\'re checking with our gateway if your transaction was successful. This won\'t take long',
|
|
style: TextStyle(fontSize: 20),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
SizedBox(height: 50,),
|
|
Image.asset('assets/velocity-animation.gif', width: 150),
|
|
SizedBox(height: 50),
|
|
if(controller.model.status == 'FAILED')
|
|
Column(
|
|
children: [
|
|
Text(
|
|
'We failed to check your transaction status',
|
|
style: TextStyle(fontSize: 20),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
SizedBox(height: 20,),
|
|
Skeletonizer(
|
|
enabled: controller.model.isLoading,
|
|
child: OutlinedButton(
|
|
child: Text('Retry'),
|
|
onPressed: () {
|
|
controller.model.isCancelled = false;
|
|
controller.pollTransaction(transactionController.model.confirmationData['id']);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|