diff --git a/lib/config/urls.dart b/lib/config/urls.dart index dedc94d..80772a7 100755 --- a/lib/config/urls.dart +++ b/lib/config/urls.dart @@ -164,6 +164,9 @@ class Url { static String changeItemStatus(String id) { return '$baseUrl/Items/ChangeStatus/$id'; } + static String changePackageStatus(String id) { + return '$baseUrl/Packages/ChangeStatus/$id'; + } static String repairItems(String id) { return '$baseUrl/transfer-items/ChangeRepair/$id'; diff --git a/lib/models/package_model.dart b/lib/models/package_model.dart index daeb44c..4b65c5b 100755 --- a/lib/models/package_model.dart +++ b/lib/models/package_model.dart @@ -33,6 +33,7 @@ class PackageDetailObject extends Equatable { final List items; final String userName; final String userCreator; + final String status; PackageDetailObject({ required this.id, @@ -44,6 +45,7 @@ class PackageDetailObject extends Equatable { required this.items, required this.userName, required this.userCreator, + required this.status }); @override diff --git a/lib/pages/PackagePages/package_result_screen.dart b/lib/pages/PackagePages/package_result_screen.dart index b540a71..b74fb04 100755 --- a/lib/pages/PackagePages/package_result_screen.dart +++ b/lib/pages/PackagePages/package_result_screen.dart @@ -230,6 +230,7 @@ class _PackageResultScreenState extends State { // 0, // items.length - 3, // ); // remove extra , + return PackageItemBox( deviceBlockSize: _deviceBlockSize, item: diff --git a/lib/providers/items.dart b/lib/providers/items.dart index 64d76a4..0f063dc 100755 --- a/lib/providers/items.dart +++ b/lib/providers/items.dart @@ -40,8 +40,10 @@ class ItemProvider extends ChangeNotifier { specific: '', ); int pageNumber = 1; + void resetPageNumber() => pageNumber = 1; bool isloading = false; + void resetLoading() { isloading = false; notifyListeners(); @@ -53,6 +55,7 @@ class ItemProvider extends ChangeNotifier { } bool isloadingButton = false; + void resetLoadingButton() { isloadingButton = false; notifyListeners(); @@ -250,24 +253,22 @@ class ItemProvider extends ChangeNotifier { items = []; searchBoxValue = value; originalItems!.forEach((result) { - if ( - result.udi - .toString() - .toLowerCase() - .contains(searchBoxValue.toLowerCase()) || - result.udi - .toString() - .toUpperCase() - .contains(searchBoxValue.toUpperCase()) || - result.udi - .toString() - .toLowerCase() - .contains(searchBoxValue.toUpperCase()) || - result.udi - .toString() - .toUpperCase() - .contains(searchBoxValue.toLowerCase()) - ) { + if (result.udi + .toString() + .toLowerCase() + .contains(searchBoxValue.toLowerCase()) || + result.udi + .toString() + .toUpperCase() + .contains(searchBoxValue.toUpperCase()) || + result.udi + .toString() + .toLowerCase() + .contains(searchBoxValue.toUpperCase()) || + result.udi + .toString() + .toUpperCase() + .contains(searchBoxValue.toLowerCase())) { items!.add(result); } }); @@ -342,7 +343,7 @@ class ItemProvider extends ChangeNotifier { size: 'null', createdAt: '2019-09-18 10:02:03', udi: 'null', - status: 0, + status: 'null', filePath: [], packageId: 'null', ); @@ -377,10 +378,11 @@ class ItemProvider extends ChangeNotifier { return result!; } - Future changeStatus(String id) async { + Future changeStatus(String id, String value) async { print(id); var response = await http.post( Uri.parse(Url.changeItemStatus(id)), + body: json.encode({'status': value}), headers: { 'Authorization': User.token, 'X-Requested-With': 'XMLHttpRequest', @@ -392,7 +394,7 @@ class ItemProvider extends ChangeNotifier { var itemData = json.decode(response.body); try { - if (itemData['status'] == 'Success') { + if (itemData['data']['transfers']['status'] == 'approved') { return true; } else { return false; @@ -404,13 +406,10 @@ class ItemProvider extends ChangeNotifier { Future exportItems() async { final baseStorage = await getExternalStorageDirectory(); - final taskId = await FlutterDownloader.enqueue( + final taskId = await FlutterDownloader.enqueue( url: Url.exportItems, savedDir: baseStorage!.path, - headers: { - 'Authorization': User.token, - "Accept": "*" - }, + headers: {'Authorization': User.token, "Accept": "*"}, showNotification: true, openFileFromNotification: true, saveInPublicStorage: true, diff --git a/lib/providers/packages.dart b/lib/providers/packages.dart index 45984ee..d7274ab 100755 --- a/lib/providers/packages.dart +++ b/lib/providers/packages.dart @@ -12,6 +12,7 @@ import 'package:http/http.dart' as http; class PackageProvider extends ChangeNotifier { List? filteredItems; + // List> itemVals = []; List itemVals = []; @@ -51,6 +52,32 @@ class PackageProvider extends ChangeNotifier { notifyListeners(); } + Future changeStatus(String id, String value) async { + print(id); + var response = await http.post( + Uri.parse(Url.changePackageStatus(id)), + body: json.encode({'status': value}), + headers: { + 'Authorization': User.token, + 'X-Requested-With': 'XMLHttpRequest', + "Content-Type": "application/json", + "Accept": "application/json" + }, + ); + + var packageData = json.decode(response.body); + + try { + if (packageData['data']['transfers']['status'] == 'approved') { + return true; + } else { + return false; + } + } catch (e) { + return false; + } + } + changeItemValByScan(String value, int index) { for (var item in filteredItems!) { if (item.udi == value) { @@ -73,8 +100,10 @@ class PackageProvider extends ChangeNotifier { // udi: '', ); int pageNumber = 1; + void resetPageNumber() => pageNumber = 1; bool isloading = false; + void resetLoading() { isloading = false; notifyListeners(); @@ -86,6 +115,7 @@ class PackageProvider extends ChangeNotifier { } bool isloadingButton = false; + void resetLoadingButton() { isloadingButton = false; notifyListeners(); @@ -331,16 +361,16 @@ class PackageProvider extends ChangeNotifier { print(response.statusCode); if (response.statusCode != 200) { return PackageDetailObject( - id: 'null', - name: 'null', - description: 'null', - createDate: '2020-07-14 13:50:42', - hospitalName: 'null', - // udi: 'null', - items: [], - userName: 'null', - userCreator: 'null', - ); + id: 'null', + name: 'null', + description: 'null', + createDate: '2020-07-14 13:50:42', + hospitalName: 'null', + // udi: 'null', + items: [], + userName: 'null', + userCreator: 'null', + status: 'null'); } var data = json.decode(response.body)['data']; List itemsList = []; @@ -353,17 +383,17 @@ class PackageProvider extends ChangeNotifier { } print(data); result = PackageDetailObject( - id: data['id'].toString(), - name: data['name'] != null ? data['name'] : '', - description: data['note'] != null ? data['note'] : '', - // udi: data['package_id'] != null ? data['package_id'] : '', - createDate: data['created_at'] != null ? data['created_at'] : '', - hospitalName: - data['user'] != null ? data['user']['medical_center']['name'] : '', - userName: data['user'] != null ? data['user']['name'] : '', - userCreator: data['creator'] != null ? data['creator']['name'] : '', - items: itemsList, - ); + id: data['id'].toString(), + name: data['name'] != null ? data['name'] : '', + description: data['note'] != null ? data['note'] : '', + // udi: data['package_id'] != null ? data['package_id'] : '', + createDate: data['created_at'] != null ? data['created_at'] : '', + hospitalName: + data['user'] != null ? data['user']['medical_center']['name'] : '', + userName: data['user'] != null ? data['user']['name'] : '', + userCreator: data['creator'] != null ? data['creator']['name'] : '', + items: itemsList, + status: data['status']); return result!; } diff --git a/lib/widgets/ItemScreens/Result/item_data_box.dart b/lib/widgets/ItemScreens/Result/item_data_box.dart index d9462b2..a81e6a7 100755 --- a/lib/widgets/ItemScreens/Result/item_data_box.dart +++ b/lib/widgets/ItemScreens/Result/item_data_box.dart @@ -31,7 +31,7 @@ class ItemItemBox extends StatelessWidget { child: Card( elevation: 1, child: Container( - padding: EdgeInsets.all(8), + padding: EdgeInsets.symmetric(vertical: 8), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -51,6 +51,7 @@ class ItemItemBox extends StatelessWidget { // width: 3 * _deviceBlockSize, // ), // Spacer(), + SizedBox(width: 4,), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -144,7 +145,8 @@ class ItemItemBox extends StatelessWidget { return AlertDialog( title: Text('Delete'), content: Text( - 'Are you sure you want delete this Item?',), + 'Are you sure you want delete this Item?', + ), actions: [ TextButton( child: Text('Yes'), @@ -172,7 +174,7 @@ class ItemItemBox extends StatelessWidget { color: Colors.black, ), ) - : userData['roles']?.contains('Supervisor') + : userData['roles']?.contains('Supervisor') ? item!.packageId != null ? InkWell( onTap: () { @@ -213,68 +215,130 @@ class ItemItemBox extends StatelessWidget { ), ) : Container() - : Container(), + : Container(), SizedBox( width: 5.0, ), userData['roles']?.contains('User') ?? false ? Container() - : InkWell( - customBorder: CircleBorder(), - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - item!.status == 1 - ? 'Are you Reject this item?' - : 'Are you Confirm this item?', + : Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Reject this item?' + ), + actions: [ + TextButton( + onPressed: () { + Provider.of(context, + listen: false) + .changeStatus(item!.id, "rejected") + .then( + (value) { + if (value) { + print('true'); + } + Navigator.of(context).pop(); + // Navigator.of(context) + // .popAndPushNamed(Routes + // .itemResultScreen); + }, + ); + }, + child: Text('Yes'), ), - actions: [ - TextButton( - onPressed: () { - Provider.of(context, - listen: false) - .changeStatus(item!.id) - .then( - (value) { - if (value) { - print('true'); - } - Navigator.of(context) - .popAndPushNamed(Routes - .itemResultScreen); - }, - ); - }, - 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: item!.status == 1 ? kPink : kBlue, - ), - child: Icon( - item!.status == 1 ? Icons.close : Icons.check, - size: 4 * _deviceBlockSize, - color: Colors.white, - ), + TextButton( + onPressed: () { + Navigator.of(context).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: 5, + ), + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Confirm this item?', + ), + actions: [ + TextButton( + onPressed: () { + Provider.of(context, + listen: false) + .changeStatus(item!.id, "approved") + .then( + (value) { + if (value) { + print('true'); + } + Navigator.of(context).pop(); + // Navigator.of(context) + // .popAndPushNamed(Routes + // .itemResultScreen); + }, + ); + }, + 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: kBlue, + ), + child: Icon( + Icons.check, + size: 4 * _deviceBlockSize, + color: Colors.white, + ), + ), + ), + ], + ), SizedBox( width: 5.0, ), @@ -304,6 +368,7 @@ class ItemItemBox extends StatelessWidget { ), ], ), + SizedBox(width: 4,) ], ), ), diff --git a/lib/widgets/PackageScreens/Details/package_detail_box.dart b/lib/widgets/PackageScreens/Details/package_detail_box.dart index f49f582..c8c80ef 100755 --- a/lib/widgets/PackageScreens/Details/package_detail_box.dart +++ b/lib/widgets/PackageScreens/Details/package_detail_box.dart @@ -264,6 +264,33 @@ class PackageDetailsDataBox extends StatelessWidget { ], ), Divider(), + SizedBox( + height: 5, + ), + Row( + children: [ + Container( + width: 35 * _deviceBlockSize, + child: Text( + 'Status', + style: TextStyle( + color: Colors.grey, + ), + ), + ), + Container( + width: 45 * _deviceBlockSize, + child: Text( + datas.status == 'approved' ? 'Confirmed' : 'Rejected', + style: TextStyle( + fontWeight: FontWeight.w700, + color: datas.status == 'approved' ? kBlue : kPink, + ), + overflow: TextOverflow.clip, + ), + ), + ], + ), SizedBox( height: 30, ), diff --git a/lib/widgets/PackageScreens/Result/package_data_box.dart b/lib/widgets/PackageScreens/Result/package_data_box.dart index c519f68..d584b82 100755 --- a/lib/widgets/PackageScreens/Result/package_data_box.dart +++ b/lib/widgets/PackageScreens/Result/package_data_box.dart @@ -6,6 +6,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; +import '../../../config/colors.dart'; import '../../../config/routes.dart'; class PackageItemBox extends StatelessWidget { @@ -127,70 +128,196 @@ class PackageItemBox extends StatelessWidget { // ), userData['roles']?.contains('User') ?? false ? Container() - : InkWell( - customBorder: CircleBorder(), - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Delete'), - content: Text( - 'Are you sure you want delete this Package?', + : userData['roles']?.contains('User') ?? false + ? Container() + : Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + 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: [ + TextButton( + child: Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + Provider.of( + context, + listen: false) + .removePackages(item!.id); + }, ), - actions: [ - TextButton( - child: Text('Yes'), - onPressed: () { - Navigator.of(context).pop(); - Provider.of( - context, - listen: false) - .removePackages(item!.id); - }, - ), - TextButton( - child: Text('No'), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - }, + TextButton( + child: Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + }, + child: Icon( + Icons.delete, + size: 5 * _deviceBlockSize, + color: Colors.black, + ), + ), + SizedBox( + width: 5.0, + ), + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Reject this item?' + ), + actions: [ + TextButton( + onPressed: () { + 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); + }, + ); + }, + 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: kPink + ), child: Icon( - Icons.delete, - size: 5 * _deviceBlockSize, - color: Colors.black, + Icons.close , + size: 4 * _deviceBlockSize, + color: Colors.white, ), ), - SizedBox( - width: 5.0, - ), - 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, + SizedBox( + width: 5, ), - ), + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Confirm this item?', + ), + actions: [ + TextButton( + onPressed: () { + 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); + }, + ); + }, + 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: kBlue, + ), + child: Icon( + Icons.check, + 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, + ), + ), + ), + ], ), + + + ], ), ],