From 7bab5a74bcd2722d155c52bf7c30a12648ee9be3 Mon Sep 17 00:00:00 2001 From: fhkhd Date: Wed, 10 Jan 2024 20:04:09 +0330 Subject: [PATCH] Fix test result status --- lib/pages/TestPages/test_result_screen.dart | 126 ++++++++++++++++-- lib/providers/test_results.dart | 1 + .../TestResultScreens/Details/datas_box.dart | 113 ++++++++++------ 3 files changed, 183 insertions(+), 57 deletions(-) diff --git a/lib/pages/TestPages/test_result_screen.dart b/lib/pages/TestPages/test_result_screen.dart index 0ba4496..715fa00 100755 --- a/lib/pages/TestPages/test_result_screen.dart +++ b/lib/pages/TestPages/test_result_screen.dart @@ -29,6 +29,7 @@ class _TestResultScreenState extends State { ScrollController? sc; bool _isInit = true; + // List _data = []; @override @@ -82,7 +83,12 @@ class _TestResultScreenState extends State { TestResultFloatingButton(deviceBlockSize: _deviceBlockSize), appBar: AppBar( titleSpacing: -10, - title: Text('Home', style: TextStyle(color: Colors.white,),), + title: Text( + 'Home', + style: TextStyle( + color: Colors.white, + ), + ), backgroundColor: Colors.black, leading: IconButton( icon: Icon( @@ -299,6 +305,7 @@ class _TestResultScreenState extends State { class TestItemBox extends StatelessWidget { final TestResultObject? item; + const TestItemBox({ Key? key, required double deviceBlockSize, @@ -347,19 +354,28 @@ class TestItemBox extends StatelessWidget { SizedBox( height: 15, ), - item!.result == 'Accepted' + (item!.verified == 'NotVerified' && + item!.result == 'Not Accepted') ? Text( - 'Accepted', - style: TextStyle( - color: kLightBlue, - ), - ) - : Text( 'Rejected', style: TextStyle( color: kPink, ), - ), + ) + : (item!.verified == 'Verified' && + item!.result == 'Accepted') + ? Text( + 'Accepted', + style: TextStyle( + color: kLightBlue, + ), + ) + : Text( + 'Pending..', + style: TextStyle( + color: Colors.grey, + ), + ) ], ), Spacer(), @@ -373,9 +389,11 @@ class TestItemBox extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - userData['roles']?.contains('User') ?? false - ? Container() - : InkWell( + (userData['roles']?.contains('User') && + item!.verified != 'verified' && + item!.hospital + .contains(userData['medical_center'])) + ? InkWell( customBorder: CircleBorder(), onTap: () { showDialog( @@ -412,7 +430,89 @@ class TestItemBox extends StatelessWidget { size: 5 * _deviceBlockSize, color: Colors.black, ), - ), + ) + : (userData['roles']?.contains('Supervisor') && + item!.verified == 'NotVerified' && + item!.result == 'Not Accepted') + ? InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text('Delete'), + content: Text( + 'Are you sure you want delete this Test?'), + actions: [ + TextButton( + child: Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + Provider.of( + context, + listen: false) + .removeTestResult(item!.id); + }, + ), + TextButton( + child: Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + }, + child: Icon( + Icons.delete, + size: 5 * _deviceBlockSize, + color: Colors.black, + ), + ) + : userData['roles']?.contains('Admin') ?? false + ? InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text('Delete'), + content: Text( + 'Are you sure you want delete this Test?'), + actions: [ + TextButton( + child: Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + Provider.of( + context, + listen: false) + .removeTestResult( + item!.id); + }, + ), + TextButton( + child: Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + }, + child: Icon( + Icons.delete, + size: 5 * _deviceBlockSize, + color: Colors.black, + ), + ) + : Container(), SizedBox( width: 7.5, ), diff --git a/lib/providers/test_results.dart b/lib/providers/test_results.dart index 56d2496..a599a88 100755 --- a/lib/providers/test_results.dart +++ b/lib/providers/test_results.dart @@ -359,6 +359,7 @@ class TestResultsProvider with ChangeNotifier { .firstWhere((element) => element.id == data['id'].toString()) .hospital, // az api safheye asli estefade mi shavad 'files': mediaList, + 'verified' : data['verified'] }; return result!; } diff --git a/lib/widgets/TestResultScreens/Details/datas_box.dart b/lib/widgets/TestResultScreens/Details/datas_box.dart index cb8102b..06ec23c 100755 --- a/lib/widgets/TestResultScreens/Details/datas_box.dart +++ b/lib/widgets/TestResultScreens/Details/datas_box.dart @@ -42,7 +42,13 @@ class DatasBox extends StatelessWidget { color: Color.fromRGBO(230, 230, 230, 1), border: Border( left: BorderSide( - color: datas['accepted'] == 'Accepted' ? kLightBlue : kPink, + color: datas['accepted'] == 'Accepted' && + datas['verified'] == 'Verified' + ? kLightBlue + : datas['accepted'] == 'Not Accepted' && + datas['verified'] == 'NotVerified' + ? kPink + : Colors.grey, width: 2, ), ), @@ -58,14 +64,26 @@ class DatasBox extends StatelessWidget { ), ), style: TextStyle( - color: datas['accepted'] == 'Accepted' ? kLightBlue : kPink, + color: datas['accepted'] == 'Accepted' && + datas['verified'] == 'Verified' + ? kLightBlue + : datas['accepted'] == 'Not Accepted' && + datas['verified'] == 'NotVerified' + ? kPink + : Colors.grey, ), ), Divider(), Text( datas['test_type_name'], style: TextStyle( - color: datas['accepted'] == 'Accepted' ? kLightBlue : kPink, + color: datas['accepted'] == 'Accepted' && + datas['verified'] == 'Verified' + ? kLightBlue + : datas['accepted'] == 'Not Accepted' && + datas['verified'] == 'NotVerified' + ? kPink + : Colors.grey, fontWeight: FontWeight.w700, ), ), @@ -198,15 +216,22 @@ class DatasBox extends StatelessWidget { Container( width: 45 * _deviceBlockSize, child: Text( - datas['accepted'] == 'Accepted' || + datas['accepted'] == 'Accepted' && datas['verified'] == 'Verified' ? 'Accepted' - : 'Rejected', + : datas['accepted'] == 'Not Accepted' && + datas['verified'] == 'NotVerified' + ? 'Rejected' + : 'Pending..', style: TextStyle( fontWeight: FontWeight.w700, - color: datas['accepted'] == 'Accepted' + color: datas['accepted'] == 'Accepted' && + datas['verified'] == 'Verified' ? kLightBlue - : kPink, + : datas['accepted'] == 'Not Accepted' && + datas['verified'] == 'NotVerified' + ? kPink + : Colors.grey, ), overflow: TextOverflow.clip, ), @@ -240,45 +265,45 @@ class DatasBox extends StatelessWidget { ), ], ), - if(datas['files'].isNotEmpty) Divider(), - if(datas['files'].isNotEmpty) SizedBox( - height: 10, - ), - if(datas['files'].isNotEmpty) Container( - width: double.infinity, - padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20), - child: CarouselSlider.builder( - disableGesture: true, - itemBuilder: (ctx, index, realIndex) { - return InkWell( - child: Image( - image: NetworkImage(datas['files'][index]) - ), - onTap: () { - showDialog( - context: context, - builder: (BuildContext context) => PinchZoom( - child: Image.network(datas['files'][index]) - ), - ); - }, - ); - }, - itemCount: datas['files'].length, - options: CarouselOptions( - enlargeCenterPage: true, - aspectRatio: 16/8, - viewportFraction: datas['files'].length == 1 ? 1 : 0.6, - padEnds: false, - pauseAutoPlayOnTouch: true, - disableCenter: false, - autoPlay: false, - enlargeFactor: 0.5, - enableInfiniteScroll: - datas['files'].length == 1 ? false : true, + if (datas['files'].isNotEmpty) Divider(), + if (datas['files'].isNotEmpty) + SizedBox( + height: 10, + ), + if (datas['files'].isNotEmpty) + Container( + width: double.infinity, + padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20), + child: CarouselSlider.builder( + disableGesture: true, + itemBuilder: (ctx, index, realIndex) { + return InkWell( + child: + Image(image: NetworkImage(datas['files'][index])), + onTap: () { + showDialog( + context: context, + builder: (BuildContext context) => PinchZoom( + child: Image.network(datas['files'][index])), + ); + }, + ); + }, + itemCount: datas['files'].length, + options: CarouselOptions( + enlargeCenterPage: true, + aspectRatio: 16 / 8, + viewportFraction: datas['files'].length == 1 ? 1 : 0.6, + padEnds: false, + pauseAutoPlayOnTouch: true, + disableCenter: false, + autoPlay: false, + enlargeFactor: 0.5, + enableInfiniteScroll: + datas['files'].length == 1 ? false : true, + ), ), ), - ), ], ), ),