disable buttons in repair mode

This commit is contained in:
fhkhd
2024-05-02 18:47:20 +04:30
parent d1b153b9c2
commit ec4da1359e
@@ -431,217 +431,225 @@ class MyItemsDetailsDataBox extends StatelessWidget {
SizedBox( SizedBox(
height: 20, height: 20,
), ),
(userData['roles']?.contains('Admin') || if (datas.repair == 0)
(userData['roles']?.contains('Supervisor') && (userData['roles']?.contains('Admin') ||
datas.packageId == null && (userData['roles']?.contains('Supervisor') &&
datas.hospital.contains(userData['medical_center'])) || datas.packageId == null &&
(userData['roles']?.contains('User') && datas.hospital.contains(userData['medical_center'])) ||
datas.packageId == null)) (userData['roles']?.contains('User') &&
? TransferDestroyButton( datas.packageId == null))
deviceBlockSize: _deviceBlockSize, ? TransferDestroyButton(
firstColor: kDarkBlue, deviceBlockSize: _deviceBlockSize,
secondColor: kDarkBlueSub, firstColor: kDarkBlue,
text: 'Transfer', secondColor: kDarkBlueSub,
onTap: () { text: 'Transfer',
push(); onTap: () {
}, push();
) },
: datas.packageId != null )
? TransferDestroyButton( : datas.packageId != null
deviceBlockSize: _deviceBlockSize, ? TransferDestroyButton(
firstColor: kDarkBlue, deviceBlockSize: _deviceBlockSize,
secondColor: kDarkBlueSub, firstColor: kDarkBlue,
text: 'Transfer', secondColor: kDarkBlueSub,
onTap: () { text: 'Transfer',
push(); onTap: () {
}, push();
) },
: Container(), )
SizedBox( : Container(),
height: 10.0, if (datas.repair == 0)
), SizedBox(
(userData['roles']?.contains('Admin') || height: 10.0,
(userData['roles']?.contains('Supervisor') && ),
datas.status != 1)) if (datas.repair == 0)
? TransferDestroyButton( (userData['roles']?.contains('Admin') ||
deviceBlockSize: _deviceBlockSize, (userData['roles']?.contains('Supervisor') &&
firstColor: Colors.black, datas.status != 1))
secondColor: Colors.black87, ? TransferDestroyButton(
text: 'Destroy', deviceBlockSize: _deviceBlockSize,
onTap: () { firstColor: Colors.black,
showDialog( secondColor: Colors.black87,
context: context, text: 'Destroy',
builder: (context) { onTap: () {
return AlertDialog( showDialog(
title: Text( context: context,
'Are you sure to destroy this Item?', builder: (context) {
style: TextStyle( return AlertDialog(
fontSize: 4 * _deviceBlockSize, title: Text(
'Are you sure to destroy this Item?',
style: TextStyle(
fontSize: 4 * _deviceBlockSize,
),
), ),
), content: SizedBox(
content: SizedBox( width: _deviceBlockSize,
width: _deviceBlockSize, height: 220,
height: 220, child: Column(
child: Column( children: [
children: [ Text(
Text( 'By approving, your item will be removed and it can not be used any more.',
'By approving, your item will be removed and it can not be used any more.',
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
),
),
SizedBox(
height: 10.0,
),
ItemCard(_deviceBlockSize),
SizedBox(
height: 20.0,
),
Consumer<ItemProvider>(
builder: (context, itemProvider, child) {
return TransferDestroyButton(
deviceBlockSize: _deviceBlockSize,
firstColor: Colors.black,
secondColor: Colors.black87,
isLoadingButton:
itemProvider.isloadingButton,
onTap: () async {
itemProvider.setLoadingButton();
await Provider.of<ItemProvider>(context,
listen: false)
.removeItems(datas.id)
.then(
(value) {
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.pushReplacementNamed(
context,
Routes.myItemsResultScreen,
);
itemProvider.resetLoadingButton();
Fluttertoast.showToast(
msg: "The item is destroyed.",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
},
);
},
text: 'Destroy',
);
},
),
SizedBox(
height: 5.0,
),
CancelTransferButton(
deviceBlockSize: _deviceBlockSize,
color: kDarkBlue,
onTap: () {
Navigator.pop(context);
},
),
],
),
),
);
},
);
},
)
: userData['roles'].contains('Supervisor')
? datas.packageId != null
? TransferDestroyButton(
deviceBlockSize: _deviceBlockSize,
firstColor: Colors.black,
secondColor: Colors.black87,
text: 'Destroy',
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'Are you sure to destroy this Item?',
style: TextStyle( style: TextStyle(
fontSize: 4 * _deviceBlockSize, fontSize: 3 * _deviceBlockSize,
), ),
), ),
content: SizedBox( SizedBox(
width: _deviceBlockSize, height: 10.0,
height: 220, ),
child: Column( ItemCard(_deviceBlockSize),
children: [ SizedBox(
Text( height: 20.0,
'By approving, your item will be removed and it can not be used any more.', ),
style: TextStyle( Consumer<ItemProvider>(
fontSize: 3 * _deviceBlockSize, builder: (context, itemProvider, child) {
), return TransferDestroyButton(
), deviceBlockSize: _deviceBlockSize,
SizedBox( firstColor: Colors.black,
height: 10.0, secondColor: Colors.black87,
), isLoadingButton:
ItemCard(_deviceBlockSize), itemProvider.isloadingButton,
SizedBox( onTap: () async {
height: 20.0, itemProvider.setLoadingButton();
), await Provider.of<ItemProvider>(
TransferDestroyButton(
deviceBlockSize: _deviceBlockSize,
firstColor: Colors.black,
secondColor: Colors.black87,
onTap: () {
Provider.of<ItemProvider>(context,
listen: false)
.removeItems(datas.id)
.then(
(value) {
Navigator.of(context).pop();
Navigator.pushReplacementNamed(
context, context,
Routes.myItemsResultScreen, listen: false)
); .removeItems(datas.id)
}, .then(
); (value) {
}, Navigator.of(context).pop();
text: 'Destroy', Navigator.of(context).pop();
), Navigator.pushReplacementNamed(
SizedBox( context,
height: 5.0, Routes.myItemsResultScreen,
), );
CancelTransferButton( itemProvider.resetLoadingButton();
deviceBlockSize: _deviceBlockSize, Fluttertoast.showToast(
color: kDarkBlue, msg: "The item is destroyed.",
onTap: () { toastLength: Toast.LENGTH_SHORT,
Navigator.pop(context); gravity: ToastGravity.BOTTOM,
}, );
), },
], );
), },
text: 'Destroy',
);
},
), ),
); SizedBox(
}, height: 5.0,
); ),
}, CancelTransferButton(
) deviceBlockSize: _deviceBlockSize,
: Container() color: kDarkBlue,
: Container(), onTap: () {
SizedBox( Navigator.pop(context);
height: 10.0, },
), ),
],
),
),
);
},
);
},
)
: userData['roles'].contains('Supervisor')
? datas.packageId != null
? TransferDestroyButton(
deviceBlockSize: _deviceBlockSize,
firstColor: Colors.black,
secondColor: Colors.black87,
text: 'Destroy',
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'Are you sure to destroy this Item?',
style: TextStyle(
fontSize: 4 * _deviceBlockSize,
),
),
content: SizedBox(
width: _deviceBlockSize,
height: 220,
child: Column(
children: [
Text(
'By approving, your item will be removed and it can not be used any more.',
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
),
),
SizedBox(
height: 10.0,
),
ItemCard(_deviceBlockSize),
SizedBox(
height: 20.0,
),
TransferDestroyButton(
deviceBlockSize: _deviceBlockSize,
firstColor: Colors.black,
secondColor: Colors.black87,
onTap: () {
Provider.of<ItemProvider>(context,
listen: false)
.removeItems(datas.id)
.then(
(value) {
Navigator.of(context).pop();
Navigator
.pushReplacementNamed(
context,
Routes.myItemsResultScreen,
);
},
);
},
text: 'Destroy',
),
SizedBox(
height: 5.0,
),
CancelTransferButton(
deviceBlockSize: _deviceBlockSize,
color: kDarkBlue,
onTap: () {
Navigator.pop(context);
},
),
],
),
),
);
},
);
},
)
: Container()
: Container(),
if (datas.repair == 0)
SizedBox(
height: 10.0,
),
(userData['roles']?.contains('Admin') || (userData['roles']?.contains('Admin') ||
userData['roles']?.contains('Supervisor')) userData['roles']?.contains('Supervisor'))
? TransferDestroyButton( ? TransferDestroyButton(
deviceBlockSize: _deviceBlockSize, deviceBlockSize: _deviceBlockSize,
firstColor: datas.repair == 1 ? kPink : Colors.green, firstColor: datas.repair == 1 ? kPink : Colors.green,
secondColor: datas.repair == 1 ? kPinkSub : Colors.lightGreen, secondColor: datas.repair == 1 ? kPinkSub : Colors.lightGreen,
text: 'Repair', text: datas.repair == 1 ? 'Exit repair mode' : 'Repair',
onTap: () { onTap: () {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return AlertDialog( return AlertDialog(
title: Text( title: Text(
'Are you sure to repair this Item?', datas.repair == 1
? 'Are you sure you want to exit repair mode for this item?'
: 'Are you sure to repair this Item?',
style: TextStyle( style: TextStyle(
fontSize: 4 * _deviceBlockSize, fontSize: 4 * _deviceBlockSize,
), ),
@@ -652,7 +660,9 @@ class MyItemsDetailsDataBox extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
Text( Text(
'By approving, your item will be set in repair mode and it can be use anymore unless you disable repair mode.', datas.repair == 1
? 'By approving, your item will come out of repair mode and will be usable again unless you enable repair mode.'
: 'By approving, your item will be set in repair mode and it can be use anymore unless you disable repair mode.',
style: TextStyle( style: TextStyle(
fontSize: 3 * _deviceBlockSize, fontSize: 3 * _deviceBlockSize,
), ),
@@ -695,7 +705,9 @@ class MyItemsDetailsDataBox extends StatelessWidget {
}, },
); );
}, },
text: 'Repair', text: datas.repair == 1
? 'Exit repair mode'
: 'Repair',
); );
}, },
), ),