import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; import 'package:go_router/go_router.dart'; import 'package:ocbo_esign_mobile/blocs/application/functions/bloc_setapplication.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/image_widget.dart'; import 'package:ocbo_esign_mobile/widgets/input_widget.dart'; import 'package:ocbo_esign_mobile/widgets/loading_widget.dart'; import 'package:ocbo_esign_mobile/widgets/text_widget.dart'; import 'package:intl/intl.dart'; class ValidateDetailPage extends StatefulWidget { const ValidateDetailPage({super.key}); @override State createState() => _ValidateDetailPageState(); } class _ValidateDetailPageState extends State { final _searchController = TextEditingController(); final NumberFormat formatter = NumberFormat('#,###'); final dateFormatter = DateFormat('yyyy-MM-dd'); // final Color greenColor = const Color(0xFF4CCE51); late bool isLoading = false; late int _total = 0; late List _applicationList = []; late List _dateList = []; late List _timeList = []; late String _name = ''; late int _count = 0; void _getTotalSigned() async { setState(() { isLoading = true; }); final name = await blocGetQr(context); final responseCount = await getApi('get-transactions-count', name, null); final total = responseCount['result']; final response = await getApi('get-transactions', name, null); final applicationNoList = response['result']; final dateList = response['result2']; final timeList = response['result3']; _name = name; setState(() { isLoading = false; _total = double.parse(total).toInt(); _count = applicationNoList.length; _applicationList = applicationNoList; _dateList = dateList; _timeList = timeList; }); } void _filterSigned(String application) async { final response = await getApi('get-transactions-filter', _name, application); final applicationNoList = response['result']; final dateList = response['result2']; final timeList = response['result3']; setState(() { // isLoading = false; // _total = double.parse(total).toInt(); _count = applicationNoList.length; _applicationList = applicationNoList; _dateList = dateList; _timeList = timeList; }); } void _onTextChanged() { _filterSigned(_searchController.text); } void _gotoInfo() { context.push('/info'); } void _showDetails(String application) async { await blocSetApplication(context, application); _gotoInfo(); } @override void initState() { _getTotalSigned(); _searchController.addListener(_onTextChanged); super.initState(); } @override void dispose() { _searchController.removeListener(_onTextChanged); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, body: Container( 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: SizedBox( width: MediaQuery.of(context).size.width - 112, child: Column( children: [ const Gap(72), BoxWidget( circular: 16, content: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ isLoading ? LoadingWidget(text: 'Loading Data, please wait') : Column( children: [ TextWidget(text: formatter.format(_total), size: 50, bold: true), const TextWidget(text: 'Total Signed Applications', size: 16), ], ), ], ), ), const Gap(16), InputWidget(controller: _searchController, password: false, placeholder: 'Filter Application Number'), const Gap(16), Expanded( flex: 1, child: ListView.builder( padding: EdgeInsets.only(bottom: 16), itemCount: _count, itemBuilder: (BuildContext context, int index) { return InkWell( onTap: () => _showDetails(_applicationList[index]), child: BoxWidget( alignment: CrossAxisAlignment.center, circular: 16, content: Row( children: [ const ImageWidget(imagePath: 'assets/esign-check.webp', size: 40, measureByHeight: true), const Gap(16), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ TextWidget(text: _applicationList[index], size: 18, bold: true), const Gap(4), SizedBox( width: 180, child: TextWidget(text: 'Date Signed: ${_dateList[index]}', size: 10, opacity: 1), ), const Gap(4), TextWidget(text: 'Time: ${_timeList[index]}', size: 10, opacity: 1), const Gap(4), const TextWidget(text: 'Tap to show details', size: 9, opacity: 0.6), ], ), ], ), ), ); }, ), ), ], ), ), ), ); } }