From 948f18d30f7b2a5b1fab62bb8e9d17b6bedf37de Mon Sep 17 00:00:00 2001 From: "hanie.khodkari" Date: Sun, 16 Mar 2025 21:14:57 +0330 Subject: [PATCH] Fix approve and reject in item result --- .../ItemScreens/Result/item_data_box.dart | 379 +++++++++++------- 1 file changed, 237 insertions(+), 142 deletions(-) diff --git a/lib/widgets/ItemScreens/Result/item_data_box.dart b/lib/widgets/ItemScreens/Result/item_data_box.dart index 9f39286..4a4d273 100755 --- a/lib/widgets/ItemScreens/Result/item_data_box.dart +++ b/lib/widgets/ItemScreens/Result/item_data_box.dart @@ -139,60 +139,246 @@ class ItemItemBox extends StatelessWidget { // SizedBox( // width: 5.0, // ), - userData['roles']?.contains('Admin') ?? false - ? InkWell( + item?.status == "suspended" || item?.status == "rejected" + ? userData['roles']?.contains('Admin') ?? false + ? InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Confirm this item?', + ), + actions: [ + Consumer(builder: + (context, itemProvider, _) { + return itemProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors.black, + ) + : TextButton( + onPressed: () async { + itemProvider + .setLoadingButton(); + await Provider.of< + ItemProvider>( + context, + listen: false) + .changeStatus( + item!.id, + "approved") + .then( + (value) { + if (value) { + print('true'); + } + Navigator.of( + context) + .pop(); + Navigator.of( + context) + .popAndPushNamed( + Routes + .itemResultScreen); + Fluttertoast + .showToast( + msg: + "Item is Confirmed.", + toastLength: Toast + .LENGTH_SHORT, + gravity: + ToastGravity + .BOTTOM, + ); + itemProvider + .resetLoadingButton(); + }, + ); + }, + child: Text('Yes'), + ); + }), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text('No'), + ), + ], + ); + }, + ); + }, + child: Container( + padding: EdgeInsets.all(7), + width: 8 * _deviceBlockSize, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: kLightBlue, + ), + child: Icon( + Icons.check, + size: 4 * _deviceBlockSize, + color: Colors.white, + ), + ), + ) + : userData['roles']?.contains('Supervisor') + ? item!.packageId != null + ? InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Confirm this item?', + ), + actions: [ + Consumer( + builder: (context, + itemProvider, _) { + return itemProvider + .isloadingButton + ? CircularProgressIndicator( + color: + Colors.black, + ) + : TextButton( + onPressed: + () async { + itemProvider + .setLoadingButton(); + await Provider.of< + ItemProvider>( + context, + listen: + false) + .changeStatus( + item! + .id, + "approved") + .then( + (value) { + if (value) { + print( + 'true'); + } + Navigator.of( + context) + .pop(); + Navigator.of( + context) + .popAndPushNamed( + Routes.itemResultScreen); + Fluttertoast + .showToast( + msg: + "Item is Confirmed.", + toastLength: + Toast + .LENGTH_SHORT, + gravity: + ToastGravity + .BOTTOM, + ); + itemProvider + .resetLoadingButton(); + }, + ); + }, + child: + Text('Yes'), + ); + }), + TextButton( + onPressed: () { + Navigator.of(context) + .pop(); + }, + child: Text('No'), + ), + ], + ); + }, + ); + }, + child: Container( + padding: EdgeInsets.all(7), + width: 8 * _deviceBlockSize, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: kLightBlue, + ), + child: Icon( + Icons.check, + size: 4 * _deviceBlockSize, + color: Colors.white, + ), + ), + ) + : Container() + : Container() + : InkWell( customBorder: CircleBorder(), onTap: () { showDialog( context: context, builder: (context) { return AlertDialog( - title: Text( - 'Are you Confirm this item?', - ), + title: Text('Are you Reject this item?'), actions: [ - Consumer(builder: - (context, itemProvider, _) { - return itemProvider.isloadingButton - ? CircularProgressIndicator( - color: Colors.black, - ) - : TextButton( - onPressed: () async { - itemProvider - .setLoadingButton(); - await Provider.of< - ItemProvider>( - context, - listen: false) - .changeStatus(item!.id, - "approved") - .then( - (value) { - if (value) { - print('true'); - } - Navigator.of(context) - .pop(); - Navigator.of(context) - .popAndPushNamed(Routes - .itemResultScreen); - Fluttertoast.showToast( - msg: - "Item is Confirmed.", - toastLength: Toast - .LENGTH_SHORT, - gravity: ToastGravity - .BOTTOM, - ); - itemProvider - .resetLoadingButton(); - }, - ); - }, - child: Text('Yes'), - ); - }), + Consumer( + builder: (context, itemProvider, _) { + return itemProvider.isloadingButton + ? CircularProgressIndicator( + color: Colors.black, + ) + : TextButton( + onPressed: () async { + itemProvider + .setLoadingButton(); + await Provider.of< + ItemProvider>( + context, + listen: false) + .changeStatus( + item!.id, + "rejected") + .then( + (value) { + if (value) { + print('true'); + } + Navigator.of(context) + .pop(); + Navigator.of(context) + .popAndPushNamed( + Routes + .itemResultScreen); + Fluttertoast + .showToast( + msg: + "Item is rejected.", + toastLength: Toast + .LENGTH_SHORT, + gravity: + ToastGravity + .BOTTOM, + ); + itemProvider + .resetLoadingButton(); + }, + ); + }, + child: Text('Yes'), + ); + }, + ), TextButton( onPressed: () { Navigator.of(context).pop(); @@ -208,106 +394,15 @@ class ItemItemBox extends StatelessWidget { padding: EdgeInsets.all(7), width: 8 * _deviceBlockSize, decoration: BoxDecoration( - shape: BoxShape.circle, - color: kLightBlue, - ), + shape: BoxShape.circle, + color: Colors.black), child: Icon( - Icons.check, + Icons.close, size: 4 * _deviceBlockSize, color: Colors.white, ), ), - ) - : userData['roles']?.contains('Supervisor') - ? item!.packageId != null - ? InkWell( - customBorder: CircleBorder(), - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - 'Are you Confirm this item?', - ), - actions: [ - Consumer(builder: - (context, itemProvider, _) { - return itemProvider - .isloadingButton - ? CircularProgressIndicator( - color: Colors.black, - ) - : TextButton( - onPressed: () async { - itemProvider - .setLoadingButton(); - await Provider.of< - ItemProvider>( - context, - listen: - false) - .changeStatus( - item!.id, - "approved") - .then( - (value) { - if (value) { - print('true'); - } - Navigator.of( - context) - .pop(); - Navigator.of( - context) - .popAndPushNamed( - Routes - .itemResultScreen); - Fluttertoast - .showToast( - msg: - "Item is Confirmed.", - toastLength: Toast - .LENGTH_SHORT, - gravity: - ToastGravity - .BOTTOM, - ); - itemProvider - .resetLoadingButton(); - }, - ); - }, - child: Text('Yes'), - ); - }), - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text('No'), - ), - ], - ); - }, - ); - }, - child: Container( - padding: EdgeInsets.all(7), - width: 8 * _deviceBlockSize, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: kLightBlue, - ), - child: Icon( - Icons.check, - size: 4 * _deviceBlockSize, - color: Colors.white, - ), - ), - ) - : Container() - : Container(), + ), SizedBox( width: 5.0, ),