Files

523 lines
31 KiB
Dart
Executable File

import 'package:cssd/models/package_model.dart';
import 'package:cssd/providers/auth.dart';
import 'package:cssd/providers/packages.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../../../config/colors.dart';
import '../../../config/routes.dart';
class PackageItemBox extends StatelessWidget {
final PackageResultObject? item;
const PackageItemBox({
Key? key,
required double deviceBlockSize,
this.item,
}) : _deviceBlockSize = deviceBlockSize,
super(key: key);
final double _deviceBlockSize;
@override
Widget build(BuildContext context) {
final userData = Provider.of<Auth>(context, listen: false).user;
return GestureDetector(
onTap: () => Navigator.of(context).pushNamed(
Routes.packageDetailScreen,
arguments: item!.id,
),
child: Card(
elevation: 1,
child: Container(
padding: EdgeInsets.all(8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
// Container(
// padding: const EdgeInsets.all(6.0),
// child: Text(
// item!.id,
// style: TextStyle(
// fontWeight: FontWeight.w700,
// fontSize: 5 * _deviceBlockSize,
// ),
// ),
// ),
// SizedBox(
// width: 3 * _deviceBlockSize,
// ),
// Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 40 * _deviceBlockSize,
child: Row(
children: [
Text(
item!.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 3 * _deviceBlockSize,
),
),
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(
width: 50 * _deviceBlockSize,
child: Row(
children: [
Text(
"ID: ",
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
color: Colors.grey,
),
),
Text(
item!.id,
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
color: Colors.black87,
),
),
Text(
" | ",
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
color: Colors.grey,
),
),
Text(
'Items: ',
style: TextStyle(
color: Colors.grey,
fontSize: 3 * _deviceBlockSize,
),
),
Text(
item!.itemsId.join(','),
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
),
),
],
),
),
Container(
width: 30 * _deviceBlockSize,
child: Row(
children: <Widget>[
Text(
"Owner: ",
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
color: Colors.grey,
),
),
Text(
item!.userName,
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
color: Colors.black87,
),
),
],
),
)
],
),
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
// userData['roles']?.contains('User') ?? false
// ? Container()
// : InkWell(
// customBorder: CircleBorder(),
// onTap: () {
// Navigator.of(context).pushNamed(
// Routes.packageUpdateScreen,
// arguments: item!.id,
// );
// },
// child: Icon(
// Icons.edit,
// size: 5 * _deviceBlockSize,
// color: Colors.black,
// ),
// ),
// SizedBox(
// width: 5.0,
// ),
userData['roles']?.contains('User') ?? false
? Container()
: userData['roles']?.contains('User') ?? false
? Container()
: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
if (userData['roles']?.contains('Admin') ||
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: <Widget>[
Consumer<
PackageProvider>(
builder: (context,
itemProvider,
_) {
return itemProvider
.isloadingButton
? CircularProgressIndicator(
color: Colors
.black,
)
: TextButton(
onPressed:
() async {
itemProvider
.setLoadingButton();
await Provider.of<PackageProvider>(context,
listen: false)
.changeStatus(item!.id, "approved")
.then(
(value) {
if (value) {
print('true');
}
Navigator.of(context).pop();
Navigator.of(context).popAndPushNamed(Routes.packageResultScreen);
Fluttertoast.showToast(
msg: "Package 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 Package?'),
actions: <Widget>[
Consumer<
PackageProvider>(
builder: (context,
itemProvider,
_) {
return itemProvider
.isloadingButton
? CircularProgressIndicator(
color: Colors
.black,
)
: TextButton(
onPressed:
() async {
itemProvider
.setLoadingButton();
await Provider.of<PackageProvider>(context, listen: false)
.changeStatus(item!.id, "rejected")
.then(
(value) {
if (value) {
print('true');
}
Navigator.of(context).pop();
Navigator.of(context).popAndPushNamed(Routes.packageResultScreen);
Fluttertoast.showToast(
msg: "Package 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 Package?',
),
actions: <Widget>[
Consumer<
PackageProvider>(
builder: (context,
itemProvider,
_) {
return itemProvider
.isloadingButton
? CircularProgressIndicator(
color: Colors
.black,
)
: TextButton(
onPressed:
() async {
itemProvider
.setLoadingButton();
await Provider.of<PackageProvider>(context,
listen: false)
.changeStatus(item!.id, "approved")
.then(
(value) {
if (value) {
print('true');
}
Navigator.of(context).pop();
Navigator.of(context).popAndPushNamed(Routes.packageResultScreen);
Fluttertoast.showToast(
msg: "Package 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,
),
InkWell(
customBorder: CircleBorder(),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Delete'),
content: Text(
'Are you sure you want delete this Package?',
),
actions: <Widget>[
TextButton(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop();
Provider.of<PackageProvider>(
context,
listen: false)
.removePackages(
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,
),
),
),
SizedBox(
width: 5,
),
// InkWell(
// customBorder: CircleBorder(),
// onTap: () {
// Navigator.of(context).pushNamed(
// Routes.packageDetailScreen,
// arguments: item!.id,
// );
// },
// child: Container(
// padding: EdgeInsets.all(7),
// width: 9 * _deviceBlockSize,
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// color: Colors.black,
// ),
// child: Icon(
// FontAwesomeIcons.fileAlt,
// size: 5 * _deviceBlockSize,
// color: Colors.white,
// ),
// ),
// ),
],
),
],
),
],
),
],
),
),
),
);
}
}