Fix access to change status of items

This commit is contained in:
hanie.khodkari
2025-04-20 18:59:29 +03:30
parent 92f20c73d8
commit 156f2a7c69
+386 -215
View File
@@ -139,20 +139,104 @@ class ItemItemBox extends StatelessWidget {
// SizedBox( // SizedBox(
// width: 5.0, // width: 5.0,
// ), // ),
item?.status == "pending" || item?.status == "rejected" if (userData['roles']?.contains('Admin') ||
? userData['roles']?.contains('Admin') ?? false (userData['roles']?.contains('Supervisor') &&
? InkWell( item!.packageId != null))
customBorder: CircleBorder(), item?.status == "pending" || item?.status == "rejected"
onTap: () { ? InkWell(
showDialog( customBorder: CircleBorder(),
context: context, onTap: () {
builder: (context) { showDialog(
return AlertDialog( context: context,
title: Text( builder: (context) {
'Are you Confirm this item?', return AlertDialog(
title: Text(
'Are you Confirm this item?',
),
actions: <Widget>[
Consumer<ItemProvider>(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'),
), ),
actions: <Widget>[ ],
Consumer<ItemProvider>(builder: );
},
);
},
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,
),
),
)
: InkWell(
customBorder: CircleBorder(),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title:
Text('Are you Reject this item?'),
actions: <Widget>[
Consumer<ItemProvider>(
builder:
(context, itemProvider, _) { (context, itemProvider, _) {
return itemProvider return itemProvider
.isloadingButton .isloadingButton
@@ -169,7 +253,7 @@ class ItemItemBox extends StatelessWidget {
listen: false) listen: false)
.changeStatus( .changeStatus(
item!.id, item!.id,
"approved") "rejected")
.then( .then(
(value) { (value) {
if (value) { if (value) {
@@ -186,7 +270,7 @@ class ItemItemBox extends StatelessWidget {
Fluttertoast Fluttertoast
.showToast( .showToast(
msg: msg:
"Item is Approved.", "Item is rejected.",
toastLength: Toast toastLength: Toast
.LENGTH_SHORT, .LENGTH_SHORT,
gravity: gravity:
@@ -200,209 +284,296 @@ class ItemItemBox extends StatelessWidget {
}, },
child: Text('Yes'), 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: <Widget>[
Consumer<ItemProvider>(
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,
),
), ),
) TextButton(
: Container() onPressed: () {
: Container() Navigator.of(context).pop();
: InkWell( },
customBorder: CircleBorder(), child: Text('No'),
onTap: () { ),
showDialog( ],
context: context, );
builder: (context) { },
return AlertDialog( );
title: Text('Are you Reject this item?'), },
actions: <Widget>[ child: Container(
Consumer<ItemProvider>( padding: EdgeInsets.all(7),
builder: (context, itemProvider, _) { width: 8 * _deviceBlockSize,
return itemProvider.isloadingButton decoration: BoxDecoration(
? CircularProgressIndicator( shape: BoxShape.circle,
color: Colors.black, color: Colors.black),
) child: Icon(
: TextButton( Icons.close,
onPressed: () async { size: 4 * _deviceBlockSize,
itemProvider color: Colors.white,
.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: <Widget>[
// Consumer<ItemProvider>(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: <Widget>[
// Consumer<ItemProvider>(
// 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: <Widget>[
// Consumer<ItemProvider>(
// 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( SizedBox(
width: 5.0, width: 5.0,
), ),