From 725b8dc30b1210cb7fd464602bc8a7d4d93a29ad Mon Sep 17 00:00:00 2001 From: fhkhd Date: Wed, 31 Jan 2024 22:24:31 +0330 Subject: [PATCH] Set progress & toast for some other events --- lib/models/package_model.dart | 2 + lib/pages/TestPages/test_verify_screen.dart | 126 ++++-- lib/providers/packages.dart | 1 + .../ItemScreens/Details/item_detail_box.dart | 28 +- .../ItemScreens/Result/item_data_box.dart | 308 ++++++++----- .../Result/package_data_box.dart | 419 ++++++++++-------- 6 files changed, 526 insertions(+), 358 deletions(-) diff --git a/lib/models/package_model.dart b/lib/models/package_model.dart index 4b65c5b..d4f9305 100755 --- a/lib/models/package_model.dart +++ b/lib/models/package_model.dart @@ -5,11 +5,13 @@ class PackageResultObject extends Equatable { final String id; final String createdAt; final String name; + final String status; PackageResultObject({ required this.id, required this.createdAt, required this.name, + required this.status }); @override diff --git a/lib/pages/TestPages/test_verify_screen.dart b/lib/pages/TestPages/test_verify_screen.dart index 13f1888..f7be2c6 100755 --- a/lib/pages/TestPages/test_verify_screen.dart +++ b/lib/pages/TestPages/test_verify_screen.dart @@ -273,6 +273,7 @@ class _TestVerifyScreenState extends State { class TestItemBox extends StatelessWidget { final TestResultObject item; + const TestItemBox({ Key? key, required String id, @@ -354,6 +355,7 @@ class TestItemBox extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.end, children: [ + item.verified == 'None' ? Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -366,29 +368,44 @@ class TestItemBox extends StatelessWidget { content: Text( 'Are you sure for verify this test?'), actions: [ - TextButton( - onPressed: () async { - Provider.of( - context, - listen: false) - .changeVerification( - item.id, 'Verified') - .then((result) { - if (result) { - print('true'); - } - Navigator.of(ctx).pop(); - Navigator.of(context).popAndPushNamed( - Routes.testVerifyScreen); - Fluttertoast.showToast( - msg: "Test is verified.", - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.BOTTOM, - ); - }); - }, - child: Text('Yes'), - ), + Consumer(builder: + (context, testResultsProvider, child) { + return testResultsProvider.isloadingButton + ? CircularProgressIndicator( + color: Colors.black, + ) + : TextButton( + onPressed: () async { + testResultsProvider + .setLoadingButton(); + await Provider.of< + TestResultsProvider>( + context, + listen: false) + .changeVerification( + item.id, 'Verified') + .then((result) { + if (result) { + print('true'); + } + Navigator.of(ctx).pop(); + Navigator.of(context) + .popAndPushNamed(Routes + .testVerifyScreen); + Fluttertoast.showToast( + msg: "Test is verified.", + toastLength: + Toast.LENGTH_SHORT, + gravity: + ToastGravity.BOTTOM, + ); + testResultsProvider + .resetLoadingButton(); + }); + }, + child: Text('Yes'), + ); + }), TextButton( onPressed: () { Navigator.of(ctx).pop(); @@ -425,28 +442,47 @@ class TestItemBox extends StatelessWidget { content: Text( 'Are you sure for reject this test?'), actions: [ - TextButton( - onPressed: () async { - await Provider.of( - context, - listen: false) - .changeVerification( - item.id, 'NotVerified') - .then((result) { - if (result) { - print('true'); - } - Navigator.of(ctx).pop(); - Navigator.of(context).popAndPushNamed( - Routes.testVerifyScreen); - Fluttertoast.showToast( - msg: "Test is rejected.", - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.BOTTOM, - ); - }); + Consumer( + builder: + (context, testResultsProvider, _) { + return testResultsProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors.black, + ) + : TextButton( + onPressed: () async { + testResultsProvider + .setLoadingButton(); + await Provider.of< + TestResultsProvider>( + context, + listen: false) + .changeVerification( + item.id, + 'NotVerified') + .then((result) { + if (result) { + print('true'); + } + Navigator.of(ctx).pop(); + Navigator.of(context) + .popAndPushNamed(Routes + .testVerifyScreen); + Fluttertoast.showToast( + msg: "Test is rejected.", + toastLength: + Toast.LENGTH_SHORT, + gravity: + ToastGravity.BOTTOM, + ); + testResultsProvider + .resetLoadingButton(); + }); + }, + child: Text('Yes'), + ); }, - child: Text('Yes'), ), TextButton( onPressed: () { @@ -473,7 +509,7 @@ class TestItemBox extends StatelessWidget { ), ), ], - ), + ) : Container(), SizedBox( width: _deviceBlockSize, ), diff --git a/lib/providers/packages.dart b/lib/providers/packages.dart index d7274ab..f6ff921 100755 --- a/lib/providers/packages.dart +++ b/lib/providers/packages.dart @@ -346,6 +346,7 @@ class PackageProvider extends ChangeNotifier { createdAt: item['created_at'], id: item['id'].toString(), name: item['name'], + status: item['status'] ), ); } diff --git a/lib/widgets/ItemScreens/Details/item_detail_box.dart b/lib/widgets/ItemScreens/Details/item_detail_box.dart index 9324c93..445aae3 100755 --- a/lib/widgets/ItemScreens/Details/item_detail_box.dart +++ b/lib/widgets/ItemScreens/Details/item_detail_box.dart @@ -12,7 +12,8 @@ class ItemDetailsDataBox extends StatelessWidget { Key? key, required this.datas, required double deviceBlockSize, - }) : _deviceBlockSize = deviceBlockSize, + }) + : _deviceBlockSize = deviceBlockSize, super(key: key); final ItemDetailObject datas; @@ -336,10 +337,14 @@ class ItemDetailsDataBox extends StatelessWidget { Container( width: 45 * _deviceBlockSize, child: Text( - datas.status == 'approved' ? 'Confirmed' : 'Rejected', + datas.status == 'approved' ? 'Confirmed' : + datas + .status == 'rejected' ? 'Rejected' : 'Pending..', style: TextStyle( fontWeight: FontWeight.w700, - color: datas.status == 'approved' ? kBlue : kPink, + color: datas.status == 'approved' ? kBlue : + datas + .status == 'rejected' ? kPink : Colors.grey, ), overflow: TextOverflow.clip, ), @@ -364,10 +369,12 @@ class ItemDetailsDataBox extends StatelessWidget { ), onTap: () { showDialog( - context: context, - builder: (BuildContext context) => PinchZoom( - child: Image.network(datas.filePath![index]) - ), + context: context, + builder: (BuildContext context) => + PinchZoom( + child: Image.network( + datas.filePath![index]) + ), ); }, ); @@ -375,7 +382,7 @@ class ItemDetailsDataBox extends StatelessWidget { itemCount: datas.filePath!.length, options: CarouselOptions( enlargeCenterPage: true, - aspectRatio: 16/8, + aspectRatio: 16 / 8, viewportFraction: datas.filePath?.length == 1 ? 1 : 0.6, padEnds: false, pauseAutoPlayOnTouch: true, @@ -383,7 +390,7 @@ class ItemDetailsDataBox extends StatelessWidget { autoPlay: false, enlargeFactor: 0.5, enableInfiniteScroll: - datas.filePath?.length == 1 ? false : true, + datas.filePath?.length == 1 ? false : true, ), ), ), @@ -394,7 +401,8 @@ class ItemDetailsDataBox extends StatelessWidget { height: 20, ), InkWell( - onTap: () async => await launch( + onTap: () async => + await launch( 'https://cssd-doc.com/Show/Item/${datas.id.toString()}', ), child: Container( diff --git a/lib/widgets/ItemScreens/Result/item_data_box.dart b/lib/widgets/ItemScreens/Result/item_data_box.dart index a81e6a7..fafe671 100755 --- a/lib/widgets/ItemScreens/Result/item_data_box.dart +++ b/lib/widgets/ItemScreens/Result/item_data_box.dart @@ -3,6 +3,7 @@ import 'package:cssd/models/item_model.dart'; import 'package:cssd/providers/auth.dart'; import 'package:cssd/providers/items.dart'; import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; @@ -51,7 +52,9 @@ class ItemItemBox extends StatelessWidget { // width: 3 * _deviceBlockSize, // ), // Spacer(), - SizedBox(width: 4,), + SizedBox( + width: 4, + ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -219,126 +222,193 @@ class ItemItemBox extends StatelessWidget { SizedBox( width: 5.0, ), - userData['roles']?.contains('User') ?? false + (userData['roles']?.contains('User') ?? false) ? Container() - : Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - InkWell( - customBorder: CircleBorder(), - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - 'Are you Reject this item?' + : item?.status == "suspended" + ? Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Reject this item?'), + actions: [ + Consumer( + builder: (context, + itemProvider, _) { + return itemProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors.black, + ) + : TextButton( + onPressed: + () async { + itemProvider + .setLoadingButton(); + await Provider.of< + ItemProvider>( + context, + listen: + false) + .changeStatus( + item!.id, + "rejected") + .then( + (value) { + if (value) { + print( + 'true'); + } + Navigator.of( + context) + .pop(); + Navigator.of( + context) + .popAndPushNamed( + Routes + .itemResultScreen); + Fluttertoast + .showToast( + msg: + "Item 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: kPink), + child: Icon( + Icons.close, + size: 4 * _deviceBlockSize, + color: Colors.white, + ), + ), ), - 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'), - ), - 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?', + SizedBox( + width: 5, ), - 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'), + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Confirm this item?', + ), + actions: [ + Consumer(builder: + (context, itemProvider, _) { + return itemProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors.black, + ) + : TextButton( + onPressed: () async { + itemProvider + .setLoadingButton(); + await Provider.of< + ItemProvider>( + context, + listen: + false) + .changeStatus( + item!.id, + "approved") + .then( + (value) { + if (value) { + print('true'); + } + Navigator.of( + context) + .pop(); + Navigator.of( + context) + .popAndPushNamed( + Routes + .itemResultScreen); + Fluttertoast + .showToast( + msg: + "Item is Confirmed.", + 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: kBlue, + ), + child: Icon( + 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: kBlue, - ), - child: Icon( - Icons.check, - size: 4 * _deviceBlockSize, - color: Colors.white, - ), - ), - ), - ], - ), + ), + ], + ) + : Container(), SizedBox( width: 5.0, ), @@ -368,7 +438,9 @@ class ItemItemBox extends StatelessWidget { ), ], ), - SizedBox(width: 4,) + SizedBox( + width: 4, + ) ], ), ), diff --git a/lib/widgets/PackageScreens/Result/package_data_box.dart b/lib/widgets/PackageScreens/Result/package_data_box.dart index d584b82..3f4eac4 100755 --- a/lib/widgets/PackageScreens/Result/package_data_box.dart +++ b/lib/widgets/PackageScreens/Result/package_data_box.dart @@ -2,6 +2,7 @@ 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:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -129,195 +130,243 @@ class PackageItemBox extends StatelessWidget { userData['roles']?.contains('User') ?? false ? Container() : 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?', + ? 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); + }, + ), + TextButton( + child: Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + }, + child: Icon( + Icons.delete, + size: 5 * _deviceBlockSize, + color: Colors.black, + ), ), - 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(); - }, - ), - ], - ); - }, - ); - }, - 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?' + item?.status == "suspended" + ? Row( + children: [ + SizedBox( + width: 5.0, + ), + InkWell( + customBorder: CircleBorder(), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you Reject this item?'), + actions: [ + Consumer< + PackageProvider>( + builder: (context, + packageProvider, + _) { + return packageProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors + .black, + ) + : TextButton( + onPressed: + () async { + packageProvider + .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, + ); + packageProvider.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: 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: [ + Consumer< + PackageProvider>( + builder: (context, + packageProvider, + _) { + return packageProvider + .isloadingButton + ? CircularProgressIndicator( + color: Colors + .black, + ) + : TextButton( + onPressed: + () async { + packageProvider + .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 Confirmed.", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + ); + packageProvider.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: kBlue, + ), + child: Icon( + Icons.check, + size: 4 * _deviceBlockSize, + color: Colors.white, + ), + ), + ), + ], + ) + : Container(), + SizedBox( + width: 5, ), - 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'), + 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, + ), ), - 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 - // .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, - ), - ), - ), - ], - ), - - - + ], + ), ], ), ],