diff --git a/lib/providers/items.dart b/lib/providers/items.dart index d442564..acca3ab 100755 --- a/lib/providers/items.dart +++ b/lib/providers/items.dart @@ -313,7 +313,8 @@ class ItemProvider extends ChangeNotifier { userName: item['user'] != null ? item['user']['name'] : '', status: item['status'], udi: item['udi'], - packageId: item['package_id'].toString(), + packageId: + item['package_id'] != null ? item['package_id'].toString() : "", ), ); } diff --git a/lib/widgets/ItemScreens/Result/item_data_box.dart b/lib/widgets/ItemScreens/Result/item_data_box.dart index 91d61cb..21b17bc 100755 --- a/lib/widgets/ItemScreens/Result/item_data_box.dart +++ b/lib/widgets/ItemScreens/Result/item_data_box.dart @@ -59,13 +59,38 @@ class ItemItemBox extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - width: 40 * _deviceBlockSize, - child: Text( - item!.name, - style: TextStyle( - fontSize: 3 * _deviceBlockSize, - fontWeight: FontWeight.w700, - ), + width: 50 * _deviceBlockSize, + child: Row( + children: [ + Text( + item!.name, + style: TextStyle( + fontSize: 3 * _deviceBlockSize, + fontWeight: FontWeight.w700, + ), + ), + if (item!.status != "approved") + Container( + margin: EdgeInsets.only(left: 5.0), + padding: EdgeInsets.symmetric( + vertical: 1, horizontal: 10), + decoration: BoxDecoration( + color: item!.status == "pending" + ? Colors.grey.withOpacity(0.2) + : kPink.withOpacity(0.05), + borderRadius: BorderRadius.circular(2)), + alignment: Alignment.center, + child: Text( + item!.status, + style: TextStyle( + fontSize: 2 * _deviceBlockSize, + color: item!.status == "pending" + ? Colors.black.withOpacity(0.5) + : kPink, + ), + ), + ) + ], ), ), Container( @@ -73,7 +98,7 @@ class ItemItemBox extends StatelessWidget { child: Row( children: [ Text( - 'Udi: ', + 'UDI: ', overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 3 * _deviceBlockSize, @@ -140,71 +165,304 @@ class ItemItemBox extends StatelessWidget { // width: 5.0, // ), if (userData['roles']?.contains('Admin') || - (userData['roles']?.contains('Supervisor') && - item!.packageId != null)) - item?.status == "pending" || item?.status == "rejected" + userData['roles']?.contains('Supervisor')) + item?.status == "pending" + ? Row( + children: [ + 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 Approved.", + 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, + ), + ), + ), + SizedBox( + width: 5.0, + ), + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + 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, + "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(); + }, + child: Text('No'), + ), + ], + ); + }, + ); + }, + child: Container( + padding: EdgeInsets.all(7), + width: 8 * _deviceBlockSize, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.black), + child: Icon( + Icons.close, + size: 4 * _deviceBlockSize, + color: Colors.white, + ), + ), + ), + ], + ) + : item?.status == "rejected" + ? 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 Approved.", + 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(), + SizedBox( + width: 5.0, + ), + if (userData['roles']?.contains('Admin') || + userData['roles']?.contains('Supervisor')) + item!.packageId == "" ? InkWell( - customBorder: CircleBorder(), onTap: () { showDialog( context: context, builder: (context) { return AlertDialog( - title: Text( - 'Are you Confirm this item?', + title: Text('Delete'), + content: Text( + 'Are you sure you want delete 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 Approved.", - toastLength: Toast - .LENGTH_SHORT, - gravity: - ToastGravity - .BOTTOM, - ); - itemProvider - .resetLoadingButton(); - }, - ); - }, - child: Text('Yes'), - ); - }), TextButton( + child: Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + Provider.of(context, + listen: false) + .removeItems(item!.id); + }, + ), + TextButton( + child: Text('No'), onPressed: () { Navigator.of(context).pop(); }, - child: Text('No'), ), ], ); @@ -216,651 +474,16 @@ class ItemItemBox extends StatelessWidget { width: 8 * _deviceBlockSize, decoration: BoxDecoration( shape: BoxShape.circle, - color: kLightBlue, + color: kPink, ), child: Icon( - Icons.check, + Icons.delete_outlined, size: 4 * _deviceBlockSize, color: Colors.white, ), ), ) - : InkWell( - customBorder: CircleBorder(), - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - 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, - "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(); - }, - child: Text('No'), - ), - ], - ); - }, - ); - }, - child: Container( - padding: EdgeInsets.all(7), - width: 8 * _deviceBlockSize, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.black), - child: Icon( - Icons.close, - size: 4 * _deviceBlockSize, - color: Colors.white, - ), - ), - ), - // item?.status == "pending" || 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 Approved.", - // 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 Approved.", - // 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 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, - // "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(); - // }, - // child: Text('No'), - // ), - // ], - // ); - // }, - // ); - // }, - // child: Container( - // padding: EdgeInsets.all(7), - // width: 8 * _deviceBlockSize, - // decoration: BoxDecoration( - // shape: BoxShape.circle, - // color: Colors.black), - // child: Icon( - // Icons.close, - // size: 4 * _deviceBlockSize, - // color: Colors.white, - // ), - // ), - // ), - SizedBox( - width: 5.0, - ), - userData['roles']?.contains('Admin') ?? false - ? InkWell( - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Delete'), - content: Text( - 'Are you sure you want delete this Item?', - ), - actions: [ - TextButton( - child: Text('Yes'), - onPressed: () { - Navigator.of(context).pop(); - Provider.of(context, - listen: false) - .removeItems(item!.id); - }, - ), - TextButton( - child: Text('No'), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - }, - child: Container( - padding: EdgeInsets.all(7), - width: 8 * _deviceBlockSize, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: kPink, - ), - child: Icon( - Icons.delete_outlined, - size: 4 * _deviceBlockSize, - color: Colors.white, - ), - ), - ) - : userData['roles']?.contains('Supervisor') - ? item!.packageId != null - ? InkWell( - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Delete'), - content: Text( - 'Are you sure you want delete this Item?', - ), - actions: [ - TextButton( - child: Text('Yes'), - onPressed: () { - Navigator.of(context).pop(); - Provider.of( - context, - listen: false) - .removeItems(item!.id); - }, - ), - TextButton( - child: Text('No'), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - }, - child: Container( - padding: EdgeInsets.all(7), - width: 8 * _deviceBlockSize, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: kPink, - ), - child: Icon( - Icons.delete_outlined, - size: 4 * _deviceBlockSize, - color: Colors.white, - ), - ), - ) - : Container() - : Container(), - - // (userData['roles']?.contains('User') ?? false) - // ? Container() - // : item?.status == "pending" - // ? Row( - // mainAxisAlignment: MainAxisAlignment.end, - // children: [ - // InkWell( - // customBorder: CircleBorder(), - // onTap: () { - // showDialog( - // context: context, - // builder: (context) { - // return AlertDialog( - // 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, - // "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(); - // }, - // child: Text('No'), - // ), - // ], - // ); - // }, - // ); - // }, - // child: Container( - // padding: EdgeInsets.all(7), - // width: 8 * _deviceBlockSize, - // decoration: BoxDecoration( - // shape: BoxShape.circle, - // color: kPink), - // child: Icon( - // Icons.close, - // size: 4 * _deviceBlockSize, - // color: Colors.white, - // ), - // ), - // ), - // SizedBox( - // width: 5, - // ), - // 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 Approved.", - // 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, ),