import 'package:cssd/config/colors.dart'; import 'package:cssd/models/my_package_model.dart'; import 'package:cssd/providers/my_packages.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import '../../../config/routes.dart'; class PackageRequestsDataBox extends StatelessWidget { final MyPackageResultObject? package; const PackageRequestsDataBox({ Key? key, required double deviceBlockSize, required this.isAdmin, this.package, }) : _deviceBlockSize = deviceBlockSize, super(key: key); final double _deviceBlockSize; final bool isAdmin; @override Widget build(BuildContext context) { return GestureDetector( onTap: () => Navigator.of(context).pushNamed( Routes.myPackagesDetailScreen, arguments: package!.id, ), child: Card( elevation: 1, child: Container( padding: EdgeInsets.all(8), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( padding: const EdgeInsets.all(6.0), child: Text( package!.id, style: TextStyle( fontWeight: FontWeight.w700, fontSize: 5 * _deviceBlockSize, ), ), ), SizedBox( width: 3 * _deviceBlockSize, ), // Spacer(), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 40 * _deviceBlockSize, child: Text( package!.name, style: TextStyle( fontSize: 3 * _deviceBlockSize, fontWeight: FontWeight.w700, ), ), ), Container( width: 30 * _deviceBlockSize, child: Row( children: [ Text( 'Date:', style: TextStyle( color: Colors.grey, fontSize: 3 * _deviceBlockSize, ), ), Text( DateFormat('y-M-d').format( DateTime.parse( package!.createdAt, ), ), style: TextStyle( fontSize: 3 * _deviceBlockSize, ), ), ], ), ), if (isAdmin) Container( width: 30 * _deviceBlockSize, child: Row( children: [ Text( 'User: ', style: TextStyle( color: Colors.grey, fontSize: 3 * _deviceBlockSize, ), ), Text( package!.userName.toString(), style: TextStyle( fontSize: 3 * _deviceBlockSize, fontWeight: FontWeight.w700, ), ), ], ), ), ], ), Spacer(), Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ Row( mainAxisAlignment: MainAxisAlignment.end, children: [ InkWell( onTap: () { showDialog( context: context, builder: (ctx) => AlertDialog( title: Text('Accept'), content: Text( 'Are you sure for approve this item?', ), actions: [ TextButton( onPressed: () async { Provider.of(context, listen: false) .verifyPackageRequests( package!.requestId!, 'approved') .then((result) { if (result) { print('true'); } Navigator.of(ctx).pop(); Navigator.of(context).popAndPushNamed( Routes.myPackagesResultScreen); }); }, child: Text('Yes'), ), TextButton( onPressed: () { Navigator.of(ctx).pop(); }, child: Text('No'), ), ], ), ); }, child: Container( padding: EdgeInsets.all(7), width: 8 * _deviceBlockSize, decoration: BoxDecoration( shape: BoxShape.circle, color: kDarkBlue, ), child: Icon( Icons.check, size: 4 * _deviceBlockSize, color: Colors.white, ), ), ), SizedBox( width: 3, ), InkWell( onTap: () { showDialog( context: context, builder: (ctx) => AlertDialog( title: Text('Reject'), content: Text( 'Are you sure for reject this item?', ), actions: [ TextButton( onPressed: () async { Provider.of(context, listen: false) .verifyPackageRequests( package!.requestId!, 'rejected') .then((result) { if (result) { print('false'); } Navigator.of(ctx).pop(); Navigator.of(context).popAndPushNamed( Routes.myPackagesResultScreen); }); }, child: Text('Yes'), ), TextButton( onPressed: () { Navigator.of(ctx).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: _deviceBlockSize, ), ], ) ], ), ], ), ), ), ); } }