import 'package:cssd/config/colors.dart'; import 'package:cssd/widgets/TestResultScreens/Main/filter_chip_box.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:provider/provider.dart'; import '../../config/routes.dart'; import '../../models/test_result_models.dart'; import '../../providers/auth.dart'; import '../../providers/test_results.dart'; import '../../widgets/TestResultScreens/Main/search_box.dart'; class TestVerifyScreen extends StatefulWidget { // static const route = '/TestVerifyScreen'; // final bool isAdmin; // TestVerifyScreen({this.isAdmin}); @override _TestVerifyScreenState createState() => _TestVerifyScreenState(); } class _TestVerifyScreenState extends State { TextEditingController searchCTRL = new TextEditingController(); ScrollController? sc; bool _isInit = true; // List _data = []; @override void initState() { sc = new ScrollController(); super.initState(); } @override void didChangeDependencies() { if (_isInit) { // setState(() { // _isLoading = true; // }); var testResults = Provider.of(context, listen: false); testResults.setLoading(); testResults.resetFilters(); testResults.resetPageNumber(); testResults.getTestResults().then((_) { testResults.resetLoading(); sc!.addListener(() { if (sc!.position.pixels == sc!.position.maxScrollExtent && searchCTRL.text == '') { var labelProviderObject = Provider.of(context, listen: false); labelProviderObject.getTestResults(); } }); // setState(() { // _isLoading = false; // }); }); _isInit = false; } super.didChangeDependencies(); } @override Widget build(BuildContext context) { final userData = Provider.of(context, listen: false).user; final _media = MediaQuery.of(context); // final double _pixelRatio = (_media.size.height / _media.size.width * 7 / 5); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; return SafeArea( child: Scaffold( appBar: AppBar( titleSpacing: -10, title: Text( 'Home', style: TextStyle( color: Colors.white, ), ), backgroundColor: Colors.black, leading: IconButton( icon: Icon( Icons.keyboard_arrow_left, color: Colors.white, size: 35, ), onPressed: () => Navigator.of(context).pushNamed(Routes.homePage), ), ), body: Padding( padding: EdgeInsets.only(top: 20, left: 20, right: 20, bottom: 60), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( // crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( // padding: EdgeInsets.only(top: 20, bottom: 40), child: Text( 'Tests To Verify', // textAlign: TextAlign.left, style: TextStyle( color: Colors.black, fontSize: 6 * _deviceBlockSize, fontWeight: FontWeight.w700, letterSpacing: 2, ), ), ), ], ), Consumer( builder: (context, testResult, _) { return Container( height: 50, child: ListView( scrollDirection: Axis.horizontal, shrinkWrap: true, children: [ testResult.filters.id != '' ? TestResultChip( deviceBlockSize: _deviceBlockSize, label: 'ID', id: '', labelID: testResult.filters.labelID, testType: testResult.filters.testType, hospital: testResult.filters.hospital, username: testResult.filters.userName, fDate: testResult.filters.fDate, uDate: testResult.filters.uDate, ) : Container(), testResult.filters.labelID != '' ? TestResultChip( deviceBlockSize: _deviceBlockSize, label: 'Label ID', id: testResult.filters.id, labelID: '', testType: testResult.filters.testType, hospital: testResult.filters.hospital, username: testResult.filters.userName, fDate: testResult.filters.fDate, uDate: testResult.filters.uDate, ) : Container(), testResult.filters.testType != '' ? TestResultChip( deviceBlockSize: _deviceBlockSize, label: 'Test Type', id: testResult.filters.id, labelID: testResult.filters.labelID, testType: '', hospital: testResult.filters.hospital, username: testResult.filters.userName, fDate: testResult.filters.fDate, uDate: testResult.filters.uDate, ) : Container(), testResult.filters.hospital != '' ? TestResultChip( deviceBlockSize: _deviceBlockSize, label: 'Hospital', id: testResult.filters.id, labelID: testResult.filters.labelID, testType: testResult.filters.testType, hospital: '', username: testResult.filters.userName, fDate: testResult.filters.fDate, uDate: testResult.filters.uDate, ) : Container(), testResult.filters.userName != '' ? TestResultChip( deviceBlockSize: _deviceBlockSize, label: 'Username', id: testResult.filters.id, labelID: testResult.filters.labelID, testType: testResult.filters.testType, hospital: testResult.filters.hospital, username: '', fDate: testResult.filters.fDate, uDate: testResult.filters.uDate, ) : Container(), testResult.filters.fDate != '' ? TestResultChip( deviceBlockSize: _deviceBlockSize, label: 'From Date', id: testResult.filters.id, labelID: testResult.filters.labelID, testType: testResult.filters.testType, hospital: testResult.filters.hospital, username: testResult.filters.userName, fDate: '', uDate: testResult.filters.uDate, ) : Container(), testResult.filters.uDate != '' ? TestResultChip( deviceBlockSize: _deviceBlockSize, label: 'Until Date', id: testResult.filters.id, labelID: testResult.filters.labelID, testType: testResult.filters.testType, hospital: testResult.filters.hospital, username: testResult.filters.userName, fDate: testResult.filters.fDate, uDate: '', ) : Container(), ], ), ); }, ), TestResultSearchBox( searchCTRL: searchCTRL, deviceBlockSize: _deviceBlockSize, ), SizedBox( height: 20, ), Expanded( child: Consumer( builder: (context, testResults, _) { return testResults.isloading ? Center( child: CircularProgressIndicator( color: Colors.black, ), ) : testResults.items?.length != 0 ? ListView.builder( controller: sc, itemBuilder: (context, index) => (testResults.items![index].verified == 'None' && userData['roles'] .contains('Supervisor')) || userData['roles'].contains('Admin') ? TestItemBox( deviceBlockSize: _deviceBlockSize, item: testResults.items![index], id: testResults.items![index].id, userData: userData, ) : Container(), itemCount: testResults.items?.length, shrinkWrap: true, ) : Container( child: Center( child: Text("There is no item to show."), ), ); }, ), ), ], ), ), ), ); } } class TestItemBox extends StatelessWidget { final TestResultObject item; const TestItemBox({ Key? key, required String id, required double deviceBlockSize, required this.item, required this.userData, }) : _deviceBlockSize = deviceBlockSize, // _id = id, super(key: key); final Map userData; final double _deviceBlockSize; // final String _id; @override Widget build(BuildContext context) { return GestureDetector( onTap: () => Navigator.of(context).pushNamed( Routes.testDetailsScreen, arguments: item.id, ), child: Card( child: Container( padding: EdgeInsets.all(10), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 57 * _deviceBlockSize, child: Text( item.name, overflow: TextOverflow.ellipsis, // style: TextStyle(fontSize: 20), ), ), Container( width: 57 * _deviceBlockSize, child: Text( item.hospital, style: TextStyle( color: Colors.grey, fontSize: 3 * _deviceBlockSize, ), ), ), SizedBox( height: 15, ), item.verified == 'None' ? Text( 'Awaiting Verification', style: TextStyle(color: Colors.orange), ) : item.verified == 'Verified' ? Text( 'Verified', style: TextStyle( color: kBlue, ), ) : Text( 'Rejected', style: TextStyle( color: kPink, ), ), ], ), Spacer(), Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ Text(item.date), SizedBox( height: 15, ), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ item.verified == 'None' ? Row( mainAxisAlignment: MainAxisAlignment.center, children: [ InkWell( onTap: () { showDialog( context: context, builder: (ctx) => AlertDialog( title: Text('Verify'), content: Text( 'Are you sure for verify this test?'), actions: [ Consumer(builder: (context, testResultsProvider, child) { return testResultsProvider .isloadingButton ? CircularProgressIndicator( color: Colors.black, ) : TextButton( onPressed: () async { testResultsProvider .setLoadingButton(); await Provider.of< TestResultsProvider>( context, listen: false) .changeVerification( item.id, 'Verified') .then((result) { if (result) { print('true'); } Navigator.of(ctx).pop(); Navigator.of(context) .popAndPushNamed(Routes .testVerifyScreen); Fluttertoast.showToast( msg: "Test is verified.", toastLength: Toast .LENGTH_SHORT, gravity: ToastGravity .BOTTOM, ); testResultsProvider .resetLoadingButton(); }); }, child: Text('Yes'), ); }), TextButton( onPressed: () { Navigator.of(ctx).pop(); }, child: Text('No'), ), ], ), ); }, child: Container( padding: EdgeInsets.all(7), width: 10 * _deviceBlockSize, decoration: BoxDecoration( shape: BoxShape.circle, color: kBlue, ), child: Icon( Icons.check, size: 6 * _deviceBlockSize, color: Colors.white, ), ), ), SizedBox( width: 3, ), InkWell( onTap: () { showDialog( context: context, builder: (ctx) => AlertDialog( title: Text('Reject'), content: Text( 'Are you sure for reject this test?'), actions: [ Consumer( builder: (context, testResultsProvider, _) { return testResultsProvider .isloadingButton ? CircularProgressIndicator( color: Colors.black, ) : TextButton( onPressed: () async { testResultsProvider .setLoadingButton(); await Provider.of< TestResultsProvider>( context, listen: false) .changeVerification( item.id, 'NotVerified') .then((result) { if (result) { print('true'); } Navigator.of(ctx) .pop(); Navigator.of(context) .popAndPushNamed( Routes .testVerifyScreen); Fluttertoast .showToast( msg: "Test is rejected.", toastLength: Toast .LENGTH_SHORT, gravity: ToastGravity .BOTTOM, ); testResultsProvider .resetLoadingButton(); }); }, child: Text('Yes'), ); }, ), TextButton( onPressed: () { Navigator.of(ctx).pop(); }, child: Text('No'), ), ], ), ); }, child: Container( padding: EdgeInsets.all(7), width: 10 * _deviceBlockSize, decoration: BoxDecoration( shape: BoxShape.circle, color: kPink, ), child: Icon( Icons.close, size: 6 * _deviceBlockSize, color: Colors.white, ), ), ), ], ) : Container(), SizedBox( width: _deviceBlockSize, ), ], ) ], ), ], ), ), ), ); } }