129 lines
4.2 KiB
Dart
129 lines
4.2 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/transaction_controller.dart';
|
|
import 'package:skeletonizer/skeletonizer.dart';
|
|
|
|
import 'integration_controller.dart';
|
|
|
|
class IntegrationScreen extends StatefulWidget {
|
|
const IntegrationScreen({super.key});
|
|
|
|
@override
|
|
State<IntegrationScreen> createState() => _IntegrationScreenState();
|
|
}
|
|
|
|
class _IntegrationScreenState extends State<IntegrationScreen> {
|
|
late IntegrationController controller;
|
|
late TransactionController transactionController;
|
|
|
|
bool integrating = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
controller = IntegrationController(context);
|
|
transactionController = Provider.of<TransactionController>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
|
|
controller.doIntegration();
|
|
}
|
|
|
|
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('/receipt');
|
|
});
|
|
}
|
|
|
|
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\'ve successfully collected your funds. We are now '
|
|
'updating your billing account. 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 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();
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|