diff --git a/lib/pages/DrawerPages/family/my-family.dart b/lib/pages/DrawerPages/family/my-family.dart index 9cd4e8a0..4c20fa05 100644 --- a/lib/pages/DrawerPages/family/my-family.dart +++ b/lib/pages/DrawerPages/family/my-family.dart @@ -12,8 +12,7 @@ import 'package:diplomaticquarterapp/extensions/string_extensions.dart'; import 'package:diplomaticquarterapp/locator.dart'; import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; -import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart' - as list; +import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart' as list; import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/pages/rateAppointment/rate_appointment_doctor.dart'; @@ -52,15 +51,12 @@ class _MyFamily extends State with TickerProviderStateMixin { var userID; TabController _tabController; int _tabIndex = 0; - AuthenticatedUserObject authenticatedUserObject = - locator(); - AppointmentRateViewModel appointmentRateViewModel = - locator(); + AuthenticatedUserObject authenticatedUserObject = locator(); + AppointmentRateViewModel appointmentRateViewModel = locator(); ProjectViewModel projectViewModel; AuthenticatedUser user; VitalSignService _vitalSignService = locator(); - PharmacyModuleViewModel pharmacyModuleViewModel = - locator(); + PharmacyModuleViewModel pharmacyModuleViewModel = locator(); ToDoCountProviderModel toDoProvider; var isVaiable = false; bool isSwitchUser = false; @@ -77,18 +73,12 @@ class _MyFamily extends State with TickerProviderStateMixin { Widget build(BuildContext context) { imagesInfo.add( ImagesInfo( - imageEn: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/0.png', - imageAr: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/0.png'), + imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/0.png'), ); imagesInfo.add( ImagesInfo( - imageEn: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/1.png', - imageAr: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/1.png'), + imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/1.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/1.png'), ); projectViewModel = Provider.of(context); toDoProvider = Provider.of(context); @@ -108,8 +98,7 @@ class _MyFamily extends State with TickerProviderStateMixin { indicatorSize: TabBarIndicatorSize.tab, labelColor: Color(0xff2B353E), unselectedLabelColor: Color(0xff575757), - labelPadding: - EdgeInsets.only(top: 15, bottom: 13, left: 20, right: 20), + labelPadding: EdgeInsets.only(top: 15, bottom: 13, left: 20, right: 20), labelStyle: TextStyle( fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins', fontSize: 16, @@ -122,20 +111,14 @@ class _MyFamily extends State with TickerProviderStateMixin { fontWeight: FontWeight.w600, letterSpacing: -0.48, ), - tabs: [ - Text(TranslationBase.of(context).family), - Text(TranslationBase.of(context).request) - ], + tabs: [Text(TranslationBase.of(context).family), Text(TranslationBase.of(context).request)], ), Expanded( child: (user != null && projectViewModel.isLogin) ? TabBarView( physics: BouncingScrollPhysics(), controller: _tabController, - children: [ - myFamilyDetails(context), - myFamilyRequest(context) - ], + children: [myFamilyDetails(context), myFamilyRequest(context)], ) : Container(child: AppText('Loading..')), ), @@ -164,95 +147,47 @@ class _MyFamily extends State with TickerProviderStateMixin { flex: 4, child: FutureBuilder( future: getFamilyFiles(), // async work - builder: (BuildContext context, - AsyncSnapshot - snapshot) { + builder: (BuildContext context, AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: - return Padding( - padding: EdgeInsets.only(top: 50), - child: Text('Loading....')); + return Padding(padding: EdgeInsets.only(top: 50), child: Text('Loading....')); default: if (snapshot.hasError) - return Padding( - padding: EdgeInsets.all(10), - child: Text( - TranslationBase.of(context).noDataAvailable)); + return Padding(padding: EdgeInsets.all(10), child: Text(TranslationBase.of(context).noDataAvailable)); else return ListView.separated( itemBuilder: (context, index) { - if (snapshot - .data - .getAllSharedRecordsByStatusList[index] - .status == - 3) + if (snapshot.data.getAllSharedRecordsByStatusList[index].status == 3) return Card( margin: EdgeInsets.all(10), shape: cardRadius(15), - color: snapshot - .data - .getAllSharedRecordsByStatusList[ - index] - .gender == - 1 - ? Color(0xff6EA8FF) - : Color(0xffFDA4B0), + color: snapshot.data.getAllSharedRecordsByStatusList[index].gender == 1 ? Color(0xff6EA8FF) : Color(0xffFDA4B0), elevation: 3, child: Container( // height: 130, - width: - MediaQuery.of(context).size.width, + width: MediaQuery.of(context).size.width, padding: EdgeInsets.all(10), child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Texts( - snapshot - .data - .getAllSharedRecordsByStatusList[ - index] - .patientName - .toLowerCase() - .capitalizeFirstofEach, + snapshot.data.getAllSharedRecordsByStatusList[index].patientName.toLowerCase().capitalizeFirstofEach, fontSize: 22, fontWeight: FontWeight.bold, color: Colors.white, ), + Texts(TranslationBase.of(context).fileNumber + ': ' + snapshot.data.getAllSharedRecordsByStatusList[index].responseID.toString(), + fontSize: 12, color: Colors.white), Texts( - TranslationBase.of(context) - .fileNumber + - ': ' + - snapshot - .data - .getAllSharedRecordsByStatusList[ - index] - .responseID - .toString(), - fontSize: 12, - color: Colors.white), - Texts( - snapshot - .data - .getAllSharedRecordsByStatusList[ - index] - .age - .toString() + + snapshot.data.getAllSharedRecordsByStatusList[index].age.toString() + ' ' + - TranslationBase.of(context) - .years + + TranslationBase.of(context).years + ', ' + - snapshot - .data - .getAllSharedRecordsByStatusList[ - index] - .genderDescription, + snapshot.data.getAllSharedRecordsByStatusList[index].genderDescription, fontSize: 12, color: Colors.white), Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ @@ -262,19 +197,11 @@ class _MyFamily extends State with TickerProviderStateMixin { setState(() { isSwitchUser = value; }); - if (isSwitchUser == - true) - switchUser( - snapshot.data - .getAllSharedRecordsByStatusList[ - index], - context); + if (isSwitchUser == true) switchUser(snapshot.data.getAllSharedRecordsByStatusList[index], context); }, ), Texts( - TranslationBase.of( - context) - .switchUser, + TranslationBase.of(context).switchUser, color: Colors.white, fontSize: 12, ) @@ -282,18 +209,12 @@ class _MyFamily extends State with TickerProviderStateMixin { ), InkWell( onTap: () { - deleteFamily( - snapshot.data - .getAllSharedRecordsByStatusList[ - index], - context); + deleteFamily(snapshot.data.getAllSharedRecordsByStatusList[index], context); }, child: Row( children: [ Texts( - TranslationBase.of( - context) - .delete, + TranslationBase.of(context).delete, color: Colors.white, fontSize: 12, ), @@ -307,13 +228,13 @@ class _MyFamily extends State with TickerProviderStateMixin { ) ], ))); + else if (checkActive(snapshot.data.getAllSharedRecordsByStatusList) == 0) + return getNoDataWidget(context); else - return SizedBox.shrink(); + return SizedBox(height: 0); }, - separatorBuilder: (context, index) => - SizedBox(height: 0), - itemCount: snapshot - .data.getAllSharedRecordsByStatusList.length); + separatorBuilder: (context, index) => SizedBox(height: 0), + itemCount: snapshot.data.getAllSharedRecordsByStatusList.length); } }, ), @@ -323,6 +244,10 @@ class _MyFamily extends State with TickerProviderStateMixin { )); } + int checkActive(List list) { + return list.where((o) => o.status == 3).toList().length; + } + Widget myFamilyRequest(context) { return //Padding( // padding: const EdgeInsets.symmetric(horizontal: 10.0), @@ -337,27 +262,18 @@ class _MyFamily extends State with TickerProviderStateMixin { child: ExpansionTile( title: Text( TranslationBase.of(context).userViewRequest, - style: TextStyle( - fontSize: 16.0, - fontWeight: FontWeight.bold, - color: Colors.black), + style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold, color: Colors.black), ), children: [ FutureBuilder( future: getUserViewRequest(), // async work - builder: (BuildContext context, - AsyncSnapshot snapshot) { + builder: (BuildContext context, AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: - return Padding( - padding: EdgeInsets.only(top: 50), - child: Text('Loading....')); + return Padding(padding: EdgeInsets.only(top: 50), child: Text('Loading....')); default: if (snapshot.hasError) - return Padding( - padding: EdgeInsets.all(10), - child: Text(TranslationBase.of(context) - .noDataAvailable)); + return Padding(padding: EdgeInsets.all(10), child: Text(TranslationBase.of(context).noDataAvailable)); else return Container( padding: EdgeInsets.all(15), @@ -370,60 +286,27 @@ class _MyFamily extends State with TickerProviderStateMixin { Padding( padding: EdgeInsets.all(10), child: Row(children: [ - Expanded( - flex: 3, - child: AppText( - TranslationBase.of( - context) - .name, - fontWeight: - FontWeight.w600)), - Expanded( - flex: 1, - child: AppText( - TranslationBase.of( - context) - .allow, - fontWeight: - FontWeight.w600)), - Expanded( - flex: 1, - child: AppText( - TranslationBase.of( - context) - .reject, - fontWeight: - FontWeight.w600)), + Expanded(flex: 3, child: AppText(TranslationBase.of(context).name, fontWeight: FontWeight.w600)), + Expanded(flex: 1, child: AppText(TranslationBase.of(context).allow, fontWeight: FontWeight.w600)), + Expanded(flex: 1, child: AppText(TranslationBase.of(context).reject, fontWeight: FontWeight.w600)), ])), - Divider( - color: Colors.black, height: 1), + Divider(color: Colors.black, height: 1), Column( - children: familyFileProvider - .allSharedRecordsByStatusResponse - .getAllSharedRecordsByStatusList - .map((result) { + children: familyFileProvider.allSharedRecordsByStatusResponse.getAllSharedRecordsByStatusList.map((result) { return Container( padding: EdgeInsets.all(10), child: Row( children: [ - Expanded( - flex: 3, - child: Text(result - .patientName)), + Expanded(flex: 3, child: Text(result.patientName)), Expanded( flex: 1, child: IconButton( icon: Icon( - Icons - .check_circle, - color: - Colors.black, + Icons.check_circle, + color: Colors.black, ), onPressed: () { - acceptRemoveRequest( - result.iD, - 3, - context); + acceptRemoveRequest(result.iD, 3, context); }, )), Expanded( @@ -431,14 +314,10 @@ class _MyFamily extends State with TickerProviderStateMixin { child: IconButton( icon: Icon( Icons.delete, - color: - Colors.black, + color: Colors.black, ), onPressed: () { - acceptRemoveRequest( - result.iD, - 4, - context); + acceptRemoveRequest(result.iD, 4, context); }, )) ], @@ -456,28 +335,18 @@ class _MyFamily extends State with TickerProviderStateMixin { child: ExpansionTile( title: Text( TranslationBase.of(context).sentRequest, - style: TextStyle( - fontSize: 16.0, - fontWeight: FontWeight.bold, - color: Colors.black), + style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold, color: Colors.black), ), children: [ FutureBuilder( future: getSentRequest(), // async work - builder: (BuildContext context, - AsyncSnapshot - snapshot) { + builder: (BuildContext context, AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: - return Padding( - padding: EdgeInsets.only(top: 50), - child: Text('Loading....')); + return Padding(padding: EdgeInsets.only(top: 50), child: Text('Loading....')); default: if (snapshot.hasError) - return Padding( - padding: EdgeInsets.all(10), - child: Text(TranslationBase.of(context) - .noDataAvailable)); + return Padding(padding: EdgeInsets.all(10), child: Text(TranslationBase.of(context).noDataAvailable)); else return Container( padding: EdgeInsets.all(15), @@ -491,45 +360,22 @@ class _MyFamily extends State with TickerProviderStateMixin { Padding( padding: EdgeInsets.all(10), child: Row(children: [ - Expanded( - flex: 3, - child: AppText( - TranslationBase.of( - context) - .theName, - fontWeight: - FontWeight.w600)), - Expanded( - flex: 2, - child: AppText( - TranslationBase.of( - context) - .status, - fontWeight: - FontWeight.w600)) + Expanded(flex: 3, child: AppText(TranslationBase.of(context).theName, fontWeight: FontWeight.w600)), + Expanded(flex: 2, child: AppText(TranslationBase.of(context).status, fontWeight: FontWeight.w600)) ])), Divider(color: Colors.black, height: 1), Column( - children: snapshot.data - .getAllSharedRecordsByStatusList - .map((result) { + children: snapshot.data.getAllSharedRecordsByStatusList.map((result) { return Padding( padding: EdgeInsets.all(10), child: Row( children: [ - Expanded( - flex: 3, - child: Text(result - .patientName)), + Expanded(flex: 3, child: Text(result.patientName)), Expanded( flex: 2, child: AppText( - result - .statusDescription, - color: - result.status == 3 - ? Colors.green - : Colors.red, + result.statusDescription, + color: result.status == 3 ? Colors.green : Colors.red, )), ], )); @@ -545,27 +391,18 @@ class _MyFamily extends State with TickerProviderStateMixin { child: ExpansionTile( title: Text( TranslationBase.of(context).userView, - style: TextStyle( - fontSize: 16.0, - fontWeight: FontWeight.bold, - color: Colors.black), + style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold, color: Colors.black), ), children: [ FutureBuilder( future: getUserViewRequest(), // async work - builder: (BuildContext context, - AsyncSnapshot snapshot) { + builder: (BuildContext context, AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: - return Padding( - padding: EdgeInsets.only(top: 50), - child: Text('Loading....')); + return Padding(padding: EdgeInsets.only(top: 50), child: Text('Loading....')); default: if (snapshot.hasError) - return Padding( - padding: EdgeInsets.all(10), - child: Text(TranslationBase.of(context) - .noDataAvailable)); + return Padding(padding: EdgeInsets.all(10), child: Text(TranslationBase.of(context).noDataAvailable)); else return Container( padding: EdgeInsets.all(15), @@ -578,33 +415,17 @@ class _MyFamily extends State with TickerProviderStateMixin { Padding( padding: EdgeInsets.all(10), child: Row(children: [ - Expanded( - flex: 3, - child: AppText( - TranslationBase.of( - context) - .name)), - Expanded( - flex: 1, - child: AppText( - TranslationBase.of( - context) - .delete)), + Expanded(flex: 3, child: AppText(TranslationBase.of(context).name)), + Expanded(flex: 1, child: AppText(TranslationBase.of(context).delete)), ])), Divider(color: Colors.black), Column( - children: familyFileProvider - .allSharedRecordsByStatusResponse - .getAllSharedRecordsByStatusList - .map((result) { + children: familyFileProvider.allSharedRecordsByStatusResponse.getAllSharedRecordsByStatusList.map((result) { return Padding( padding: EdgeInsets.all(10), child: Row( children: [ - Expanded( - flex: 3, - child: AppText(result - .patientName)), + Expanded(flex: 3, child: AppText(result.patientName)), Expanded( flex: 1, child: IconButton( @@ -613,10 +434,7 @@ class _MyFamily extends State with TickerProviderStateMixin { color: Colors.black, ), onPressed: () { - deactivateRequest( - result.iD, - 5, - context); + deactivateRequest(result.iD, 5, context); }, )), ], @@ -646,10 +464,9 @@ class _MyFamily extends State with TickerProviderStateMixin { Future getFamilyFiles() async { if (await sharedPref.getObject(FAMILY_FILE) != null) { - return Future.value(GetAllSharedRecordsByStatusResponse.fromJson( - await sharedPref.getObject(FAMILY_FILE))); + return Future.value(GetAllSharedRecordsByStatusResponse.fromJson(await sharedPref.getObject(FAMILY_FILE))); } else { - return familyFileProvider.getSharedRecordByStatus().then((value) {}); + return familyFileProvider.getSharedRecordByStatus(); } } @@ -669,10 +486,7 @@ class _MyFamily extends State with TickerProviderStateMixin { confirmMessage: TranslationBase.of(context).removeFamilyMember, okText: TranslationBase.of(context).confirm, cancelText: TranslationBase.of(context).cancel_nocaps, - okFunction: () => { - ConfirmDialog.closeAlertDialog(context), - removeFamily(family, context) - }, + okFunction: () => {ConfirmDialog.closeAlertDialog(context), removeFamily(family, context)}, cancelFunction: () => {}); dialog.showAlertDialog(context); } @@ -683,10 +497,7 @@ class _MyFamily extends State with TickerProviderStateMixin { Map request = {}; request['ID'] = this.userID; request['IsActive'] = false; - this - .familyFileProvider - .deativateActivateMemberFile(request) - .then((value) => refreshFamily(context)); + this.familyFileProvider.deativateActivateMemberFile(request).then((value) => refreshFamily(context)); } refreshFamily(context) { @@ -704,12 +515,7 @@ class _MyFamily extends State with TickerProviderStateMixin { // .then((value) => loginAfter(value, context)); // Utils.showProgressDialog(context); - this - .familyFileProvider - .silentLoggin(user is AuthenticatedUser ? null : user, - mainUser: user is AuthenticatedUser) - .then((value) => loginAfter(value, context)) - .catchError((err) { + this.familyFileProvider.silentLoggin(user is AuthenticatedUser ? null : user, mainUser: user is AuthenticatedUser).then((value) => loginAfter(value, context)).catchError((err) { print(err); AppToast.showErrorToast(message: err); Navigator.of(context).pop(); @@ -718,8 +524,7 @@ class _MyFamily extends State with TickerProviderStateMixin { loginAfter(result, context) async { var currentLang = await sharedPref.getString(APP_LANGUAGE); - Provider.of(context, listen: false) - .setPrivilege(privilegeList: result, isLoginChild: true); + Provider.of(context, listen: false).setPrivilege(privilegeList: result, isLoginChild: true); result = list.CheckActivationCode.fromJson(result); var familyFile = await sharedPref.getObject(FAMILY_FILE); @@ -740,10 +545,8 @@ class _MyFamily extends State with TickerProviderStateMixin { this.sharedPref.setString(TOKEN, result.authenticationTokenID); await authenticatedUserObject.getUser(getUser: true); - Provider.of(context, listen: false).user = - authenticatedUserObject.user; - Provider.of(context, listen: false) - .setUser(authenticatedUserObject.user); + Provider.of(context, listen: false).user = authenticatedUserObject.user; + Provider.of(context, listen: false).setUser(authenticatedUserObject.user); appointmentRateViewModel .getIsLastAppointmentRatedList() @@ -781,8 +584,7 @@ class _MyFamily extends State with TickerProviderStateMixin { Map request = {}; request["ID"] = ID; request["Status"] = status; - this.familyFileProvider.deactivateFamily(request).then((value) => - {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)}); + this.familyFileProvider.deactivateFamily(request).then((value) => {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)}); } acceptRemoveRequest(ID, status, context) { @@ -790,17 +592,14 @@ class _MyFamily extends State with TickerProviderStateMixin { Map request = {}; request["ID"] = ID; request["Status"] = status; - this.familyFileProvider.acceptRejectFamily(request).then((value) => - {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)}); + this.familyFileProvider.acceptRejectFamily(request).then((value) => {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)}); } checkUserData() async { if (await this.sharedPref.getObject(USER_PROFILE) != null) { - var data = AuthenticatedUser.fromJson( - await this.sharedPref.getObject(USER_PROFILE)); + var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE)); - var data2 = AuthenticatedUser.fromJson( - await this.sharedPref.getObject(MAIN_USER)); + var data2 = AuthenticatedUser.fromJson(await this.sharedPref.getObject(MAIN_USER)); setState(() { this.user = data; }); @@ -813,8 +612,7 @@ class _MyFamily extends State with TickerProviderStateMixin { service.getActiveAppointmentNo(context).then((res) { print(res['AppointmentActiveNumber']); if (res['MessageStatus'] == 1 && res['AppointmentActiveNumber'] != null) { - toDoProvider.setState(res['AppointmentActiveNumber'], true, - toDoProvider.notificationsCount); + toDoProvider.setState(res['AppointmentActiveNumber'], true, toDoProvider.notificationsCount); } else {} }).catchError((err) { print(err);