From 0a9ca94d051f2cd6ab3f1d671552a35e142c0033 Mon Sep 17 00:00:00 2001 From: "hanie.khodkari" Date: Wed, 23 Apr 2025 19:10:52 +0330 Subject: [PATCH] Change some ui in package result --- lib/models/package_model.dart | 31 +- lib/providers/packages.dart | 3 +- .../Result/package_data_box.dart | 338 +++++++++++++++++- 3 files changed, 340 insertions(+), 32 deletions(-) diff --git a/lib/models/package_model.dart b/lib/models/package_model.dart index d4f9305..73c4b68 100755 --- a/lib/models/package_model.dart +++ b/lib/models/package_model.dart @@ -6,12 +6,14 @@ class PackageResultObject extends Equatable { final String createdAt; final String name; final String status; + final String userName; PackageResultObject({ required this.id, required this.createdAt, required this.name, - required this.status + required this.status, + required this.userName, }); @override @@ -31,24 +33,24 @@ class PackageDetailObject extends Equatable { final String description; final String createDate; final String hospitalName; + // final String udi; final List items; - final String userName; + final String userName; final String userCreator; final String status; - PackageDetailObject({ - required this.id, - required this.name, - required this.description, - required this.createDate, - required this.hospitalName, - // required this.udi, - required this.items, - required this.userName, - required this.userCreator, - required this.status - }); + PackageDetailObject( + {required this.id, + required this.name, + required this.description, + required this.createDate, + required this.hospitalName, + // required this.udi, + required this.items, + required this.userName, + required this.userCreator, + required this.status}); @override List get props { @@ -73,6 +75,7 @@ class PackageFilterObject extends Equatable { final String id; final String name; final String hospital; + // final String udi; PackageFilterObject({ diff --git a/lib/providers/packages.dart b/lib/providers/packages.dart index ff161c7..aac2c93 100755 --- a/lib/providers/packages.dart +++ b/lib/providers/packages.dart @@ -401,7 +401,8 @@ class PackageProvider extends ChangeNotifier { createdAt: item['created_at'], id: item['id'].toString(), name: item['name'], - status: item['status']), + status: item['status'], + userName: item['user']['name']), ); } pageNumber += 1; diff --git a/lib/widgets/PackageScreens/Result/package_data_box.dart b/lib/widgets/PackageScreens/Result/package_data_box.dart index d197a56..8de8473 100755 --- a/lib/widgets/PackageScreens/Result/package_data_box.dart +++ b/lib/widgets/PackageScreens/Result/package_data_box.dart @@ -3,7 +3,6 @@ import 'package:cssd/providers/auth.dart'; import 'package:cssd/providers/packages.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -55,24 +54,81 @@ class PackageItemBox extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - width: 30 * _deviceBlockSize, - child: Text( - item!.id, - style: TextStyle( - fontSize: 3 * _deviceBlockSize, - color: Colors.grey, - ), + 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: 40 * _deviceBlockSize, - child: Text( - item!.name, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontWeight: FontWeight.w700, - fontSize: 3 * _deviceBlockSize, - ), + 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( + "Owner: ", + style: TextStyle( + fontSize: 3 * _deviceBlockSize, + color: Colors.grey, + ), + ), + Text( + item!.userName, + style: TextStyle( + fontSize: 3 * _deviceBlockSize, + color: Colors.black87, + ), + ), + ], ), ), Container( @@ -80,7 +136,7 @@ class PackageItemBox extends StatelessWidget { child: Row( children: [ Text( - 'Date:', + 'Items: ', style: TextStyle( color: Colors.grey, fontSize: 3 * _deviceBlockSize, @@ -134,6 +190,254 @@ class PackageItemBox extends StatelessWidget { : Row( mainAxisAlignment: MainAxisAlignment.end, children: [ + 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: [ + Consumer< + PackageProvider>( + builder: (context, + itemProvider, + _) { + return itemProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors + .black, + ) + : TextButton( + onPressed: + () async { + itemProvider + .setLoadingButton(); + await Provider.of(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: [ + Consumer< + PackageProvider>( + builder: (context, + itemProvider, + _) { + return itemProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors + .black, + ) + : TextButton( + onPressed: + () async { + itemProvider + .setLoadingButton(); + await Provider.of(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: [ + Consumer< + PackageProvider>( + builder: (context, + itemProvider, + _) { + return itemProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors + .black, + ) + : TextButton( + onPressed: + () async { + itemProvider + .setLoadingButton(); + await Provider.of(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: () {