import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; import 'package:intl/intl.dart'; import 'package:ocbo_esign_mobile/blocs/application/functions/bloc_getapplication.dart'; import 'package:ocbo_esign_mobile/blocs/qr/functions/bloc_getqr.dart'; import 'package:ocbo_esign_mobile/functions/get_api.dart'; import 'package:ocbo_esign_mobile/widgets/box_widget.dart'; import 'package:ocbo_esign_mobile/widgets/loading_widget.dart'; import 'package:ocbo_esign_mobile/widgets/text_widget.dart'; class ApplicationInfoPage extends StatefulWidget { const ApplicationInfoPage({super.key}); @override State createState() => _ApplicationInfoPageState(); } class _ApplicationInfoPageState extends State { // final NumberFormat formatter = NumberFormat('#,###.##'); final NumberFormat formatter = NumberFormat.currency(symbol: '₱ ', decimalDigits: 2); late String _applicationNo = ''; late String _name = ''; late String _monthApproved = ''; late String _dayApproved = ''; late String _yearApproved = ''; late String _monthPrinted = ''; late String _dayPrinted = ''; late String _yearPrinted = ''; late String _amount = ''; late bool _isLoading = false; void _getInfo() async { setState(() { _isLoading = true; }); late String applicationBloc = ''; late String qrBloc = ''; if (context.mounted) { applicationBloc = await blocGetApplication(context); // ignore: use_build_context_synchronously qrBloc = await blocGetQr(context); } final id = await getApi('get-esignid-byname', qrBloc, null); final responseApproval = await getApi('get-infoapproval-electrical', applicationBloc, id["result"].toString()); final responsePrinted = await getApi('get-infoprinted-electrical', applicationBloc, id["result"].toString()); final responseAmount = await getApi('get-totalamount-electrical', applicationBloc, null); final formattedAmount = formatter.format(double.parse(responseAmount["result"].toString())); setState(() { _applicationNo = applicationBloc; _name = responseApproval["result"].toString(); _monthApproved = responseApproval["result2"].toString(); _dayApproved = responseApproval["result3"].toString(); _yearApproved = responseApproval["result4"].toString(); _monthPrinted = responsePrinted["result"].toString(); _dayPrinted = responsePrinted["result2"].toString(); _yearPrinted = responsePrinted["result3"].toString(); _amount = formattedAmount; _isLoading = false; }); } @override void initState() { _getInfo(); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, body: Container( padding: EdgeInsets.only(left: 16, right: 16), alignment: Alignment.center, height: MediaQuery.of(context).size.height, decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Color.fromRGBO(37, 25, 44, 1), Color.fromRGBO(22, 33, 44, 1), Color.fromRGBO(22, 33, 44, 1), Color.fromRGBO(22, 33, 44, 1), Color.fromRGBO(25, 46, 41, 1), ], ), ), child: Column( children: [ const Gap(88), BoxWidget( circular: 16, padding: EdgeInsets.all(8), content: _isLoading ? Center(child: LoadingWidget(text: 'Gathering Data, please wait')) : Center(child: TextWidget(text: _applicationNo, bold: true, size: 30)), ), const Gap(16), BoxWidget( circular: 16, padding: EdgeInsets.all(8), content: Center( child: Column( children: [ const TextWidget( text: 'Name of Owner', bold: false, size: 8, color: Color.fromRGBO(255, 255, 255, 0.8), ), const Gap(4), TextWidget(text: _name, bold: false, size: 16), ], ), ), ), const Gap(8), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ BoxWidget( circular: 16, width: 140, padding: EdgeInsets.all(0), content: Center( child: Column( children: [ const TextWidget( text: 'Approved Date', bold: false, size: 8, color: Color.fromRGBO(255, 255, 255, 0.8), ), const Gap(4), TextWidget(text: _monthApproved, bold: false, size: 16), TextWidget(text: _dayApproved, bold: true, size: 40), TextWidget(text: _yearApproved, bold: false, size: 16), ], ), ), ), BoxWidget( circular: 16, width: 140, padding: EdgeInsets.all(0), content: Center( child: Column( children: [ const TextWidget( text: 'Printed Date', bold: false, size: 8, color: Color.fromRGBO(255, 255, 255, 0.8), ), const Gap(4), TextWidget(text: _monthPrinted, bold: false, size: 16), TextWidget(text: _dayPrinted, bold: true, size: 40), TextWidget(text: _yearPrinted, bold: false, size: 16), ], ), ), ), ], ), const Gap(8), BoxWidget( circular: 16, padding: EdgeInsets.all(8), content: Center( child: Column( children: [ const TextWidget( text: 'Total Amount', bold: false, size: 8, color: Color.fromRGBO(255, 255, 255, 0.8), ), const Gap(4), TextWidget(text: _amount, bold: true, size: 32), ], ), ), ), ], ), ), ); } }