From fd73c248e2d2a74c46ae034a8cf8bd1f339b6acb Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Thu, 17 Mar 2022 17:46:24 +0300 Subject: [PATCH 1/2] my family switch profile improvement. --- lib/core/service/client/base_app_client.dart | 2 +- lib/core/viewModels/base_view_model.dart | 8 +- lib/pages/DrawerPages/family/my-family.dart | 837 ++++++++---------- .../fragments/home_page_fragment2.dart | 2 + .../family_files/family_files_provider.dart | 2 +- lib/theme/colors.dart | 1 + 6 files changed, 377 insertions(+), 475 deletions(-) diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index 2e237660..e96d7283 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -635,7 +635,7 @@ class BaseAppClient { String getSessionId(String id) { ///return id.replaceAll(RegExp('/[^\w\s]/'), ''); - return id.replaceAll(RegExp('/[^a-zA-Z ]'), ''); + return id.replaceAll(RegExp('/[^a-zA-Z]'), ''); } static defaultHttpParameters() async { diff --git a/lib/core/viewModels/base_view_model.dart b/lib/core/viewModels/base_view_model.dart index 338fd339..46a36c27 100644 --- a/lib/core/viewModels/base_view_model.dart +++ b/lib/core/viewModels/base_view_model.dart @@ -24,22 +24,20 @@ class BaseViewModel extends ChangeNotifier { void setState(ViewState viewState) { _state = viewState; - if (viewState == ViewState.Busy || viewState == ViewState.BusyLocal) - error = ""; + if (viewState == ViewState.Busy || viewState == ViewState.BusyLocal) error = ""; if (hasListeners) notifyListeners(); } - setUser(AuthenticatedUser user){ + setUser(AuthenticatedUser user, {bool notify = true}) { this.user = user; - notifyListeners(); + if (notify) notifyListeners(); } BaseViewModel() { //authenticatedUserObject.getUser(); user = authenticatedUserObject.user; this.isLogin = authenticatedUserObject.isLogin; - } _getUser() async { diff --git a/lib/pages/DrawerPages/family/my-family.dart b/lib/pages/DrawerPages/family/my-family.dart index 54ca8ce7..daf7a650 100644 --- a/lib/pages/DrawerPages/family/my-family.dart +++ b/lib/pages/DrawerPages/family/my-family.dart @@ -19,6 +19,7 @@ import 'package:diplomaticquarterapp/pages/rateAppointment/rate_appointment_doct import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart'; import 'package:diplomaticquarterapp/services/family_files/family_files_provider.dart'; +import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; @@ -83,7 +84,7 @@ class _MyFamily extends State with TickerProviderStateMixin { 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); + toDoProvider = Provider.of(context, listen: false); return AppScaffold( appBarTitle: TranslationBase.of(context).myFamilyFiles, isShowAppBar: widget.isAppbarVisible, @@ -125,155 +126,117 @@ class _MyFamily extends State with TickerProviderStateMixin { ) : Container(child: AppText('')), ), + DefaultButton( + TranslationBase.of(context).addFamilyMember, + () async { + Navigator.of(context).pushNamed(ADD_FAMILY_MEMBER_TYPE); + }, + ).insideContainer, ], ), - bottomSheet: Container( - color: Theme.of(context).scaffoldBackgroundColor, - width: double.infinity, - padding: EdgeInsets.all(14), - child: DefaultButton( - TranslationBase.of(context).addFamilyMember, - () async { - Navigator.of(context).pushNamed(ADD_FAMILY_MEMBER_TYPE); - }, - ), - ), ); } Widget myFamilyDetails(context) { - return Container( - margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0), - child: Column( - children: [ - Expanded( - flex: 4, - child: FutureBuilder( - future: getFamilyFiles(), // async work - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.waiting: - 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)); - else - return checkActive(snapshot.data.getAllSharedRecordsByStatusList) > 0 - ? ListView.separated( - itemBuilder: (context, index) { - if (snapshot.data.getAllSharedRecordsByStatusList[index].status == 3) - return Container( - margin: EdgeInsets.all(5), - decoration: cardRadius( - 15, - elevation: 0, - color: snapshot.data.getAllSharedRecordsByStatusList[index].gender == 2 ? Color(0xffFDA4B0) : Color(0xff6EA8FF), - ), - child: Container( - // height: 130,0xffFDA4B0 - width: MediaQuery.of(context).size.width, - padding: EdgeInsets.all(10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Texts( - snapshot.data.getAllSharedRecordsByStatusList[index].patientName.toLowerCase().capitalizeFirstofEach, - fontSize: 18, - fontWeight: FontWeight.bold, - 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() + - ' ' + - TranslationBase.of(context).years + - ', ' + - snapshot.data.getAllSharedRecordsByStatusList[index].genderDescription, - fontSize: 12, - color: Colors.white), - ], - ), - Column( - children: [ - SizedBox(height: 10), - InkWell( - onTap: () { - switchUser(snapshot.data.getAllSharedRecordsByStatusList[index], context); - }, - child: Container( - decoration: BoxDecoration(color: Colors.black.withOpacity(0.1), borderRadius: BorderRadius.circular(20)), - padding: EdgeInsets.fromLTRB(15, 10, 15, 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SvgPicture.asset("assets/images/new-design/switch.svg", - height: 22, color: snapshot.data.getAllSharedRecordsByStatusList[index].gender == 2 ? Color(0Xff5A282E) : Colors.white), - SizedBox( - width: 5, - ), - // CupertinoSwitch( - // value: isSwitchUser, - // onChanged: (value) { - // setState(() { - // isSwitchUser = value; - // }); - // if (isSwitchUser == true) switchUser(snapshot.data.getAllSharedRecordsByStatusList[index], context); - // }, - // ), - Texts(TranslationBase.of(context).switchUser, - color: snapshot.data.getAllSharedRecordsByStatusList[index].gender == 2 ? Color(0Xff5A282E) : Colors.white, - fontSize: 12, - fontWeight: FontWeight.w600) - ], - ))), - SizedBox( - height: 10, - ), - InkWell( - onTap: () { - deleteFamily(snapshot.data.getAllSharedRecordsByStatusList[index], context); - }, - child: Container( - decoration: BoxDecoration(color: Colors.black.withOpacity(0.1), borderRadius: BorderRadius.circular(20)), - padding: EdgeInsets.fromLTRB(15, 10, 15, 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SvgPicture.asset("assets/images/new-design/delete.svg", - height: 22, color: snapshot.data.getAllSharedRecordsByStatusList[index].gender == 2 ? Color(0Xff5A282E) : Colors.white), - SizedBox( - width: 5, - ), - Texts(TranslationBase.of(context).delete, - color: snapshot.data.getAllSharedRecordsByStatusList[index].gender == 2 ? Color(0Xff5A282E) : Colors.white, - fontSize: 12, - fontWeight: FontWeight.w600), - ], - ))), - SizedBox(height: 10), - ], - ), - ], - ))); - // else if (checkActive(snapshot.data.getAllSharedRecordsByStatusList) == 0) - // return getNoDataWidget(context); - else - return SizedBox(height: 0); - }, - separatorBuilder: (context, index) => SizedBox(height: 0), - itemCount: snapshot.data.getAllSharedRecordsByStatusList.length) - : getNoDataWidget(context); - } - }, - ), - ), - SizedBox(height: 80.0) - ], - )); + return (familySharedRecordsList.length ?? 0) > 0 + ? ListView.separated( + padding: EdgeInsets.all(21), + itemBuilder: (context, index) { + bool isFemale = familySharedRecordsList[index].gender == 2; + if (familySharedRecordsList[index].status == 3) { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all( + Radius.circular(15), + ), + gradient: LinearGradient( + colors: isFemale + ? [ + Color(0xFFFBC8CC), + Color(0xFFFDA4B0), + ] + : [ + Color(0xFF7AB8FD), + Color(0xFF6EA8FF), + ], + begin: Alignment.topRight, + end: Alignment.bottomLeft, + ), + ), + child: Container( + width: MediaQuery.of(context).size.width, + padding: EdgeInsets.all(15), + child: Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + familySharedRecordsList[index].patientName.toLowerCase().capitalizeFirstofEach, + style: TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: isFemale ? Color(0xff5A282E) : Colors.white, letterSpacing: -0.42), + ), + Text( + TranslationBase.of(context).fileNumber + ': ' + familySharedRecordsList[index].responseID.toString(), + style: TextStyle(fontSize: 12, fontWeight: FontWeight.w400, color: isFemale ? Color(0xff5A282E) : Colors.white, letterSpacing: -0.4, height: 16 / 10), + ), + Text( + familySharedRecordsList[index].age.toString() + ' ' + TranslationBase.of(context).years + ', ' + familySharedRecordsList[index].genderDescription, + style: TextStyle(fontSize: 12, fontWeight: FontWeight.w400, color: isFemale ? Color(0xff5A282E) : Colors.white, letterSpacing: -0.4, height: 16 / 10), + ), + ], + ), + ), + SizedBox(width: 4), + Column( + children: [ + InkWell( + onTap: () { + switchUser(familySharedRecordsList[index], context); + }, + child: Container( + decoration: BoxDecoration(color: Colors.black.withOpacity(0.1), borderRadius: BorderRadius.circular(20)), + padding: EdgeInsets.fromLTRB(10, 8, 12, 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SvgPicture.asset("assets/images/new-design/switch.svg", height: 16, color: isFemale ? Color(0Xff5A282E) : Colors.white), + SizedBox(width: 4), + Texts(TranslationBase.of(context).switchUser, color: isFemale ? Color(0Xff5A282E) : Colors.white, fontSize: 12, fontWeight: FontWeight.w600) + ], + ), + ), + ), + SizedBox(height: 8), + InkWell( + onTap: () { + deleteFamily(familySharedRecordsList[index], context); + }, + child: Container( + decoration: BoxDecoration(color: Colors.black.withOpacity(0.1), borderRadius: BorderRadius.circular(20)), + padding: EdgeInsets.fromLTRB(10, 8, 12, 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SvgPicture.asset("assets/images/new-design/delete.svg", height: 16, color: isFemale ? Color(0Xff5A282E) : Colors.white), + SizedBox(width: 4), + Texts(TranslationBase.of(context).delete, color: isFemale ? Color(0Xff5A282E) : Colors.white, fontSize: 12, fontWeight: FontWeight.w600), + ], + ), + ), + ), + ], + ), + ], + ), + ), + ); + } else + return SizedBox(height: 0); + }, + separatorBuilder: (context, index) => SizedBox(height: 0), + itemCount: familySharedRecordsList.length) + : getNoDataWidget(context); } int checkActive(List list) { @@ -281,287 +244,175 @@ class _MyFamily extends State with TickerProviderStateMixin { } Widget myFamilyRequest(context) { - return //Padding( - // padding: const EdgeInsets.symmetric(horizontal: 10.0), - // child: - SingleChildScrollView( - child: Container( - height: MediaQuery.of(context).size.height, - margin: EdgeInsets.only(top: 10), - child: Column( - children: [ - FractionallySizedBox( - widthFactor: 1.0, - child: AppExpandableNotifier( - title: TranslationBase.of(context).userViewRequest, - bodyWidget: FutureBuilder( - future: getUserViewRequest(), // async work - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.waiting: - return SizedBox(); - - default: - if (snapshot.hasError) - return Padding(padding: EdgeInsets.all(10), child: Text(TranslationBase.of(context).noDataAvailable)); - else - return ListView.separated( - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - padding: EdgeInsets.only(bottom: 14, top: 14, left: 21, right: 21), - itemBuilder: (context, _index) { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(10.0), - ), - border: Border.all(width: 1, color: Color(0xffEFEFEF)), - boxShadow: [ - BoxShadow( - color: Color(0xff000000).withOpacity(.05), - //spreadRadius: 5, - blurRadius: 27, - offset: Offset(0, -3), - ), - ], - color: Colors.white), - child: Column( - children: [ - Column(children: [ - 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)), - ])), - Padding( - padding: const EdgeInsets.only(left: 10.0, right: 10.0), - child: Divider(color: Colors.black, height: 1.5, thickness: 1.5), - ), - Column( - children: familyFileProvider.allSharedRecordsByStatusResponse.getAllSharedRecordsByStatusList.map((result) { - return Container( - padding: EdgeInsets.all(10), - child: Row( - children: [ - Expanded( - flex: 3, - child: Texts( - result.patientName, - fontWeight: FontWeight.w600, - fontSize: 12, - )), - Expanded( - flex: 1, - child: IconButton( - icon: SvgPicture.asset("assets/images/new-design/allow.svg", height: 22), - onPressed: () { - acceptRemoveRequest(result.iD, 3, context); - }, - )), - Expanded( - flex: 1, - child: IconButton( - icon: SvgPicture.asset("assets/images/new-design/reject.svg", height: 22), - color: Colors.white, - onPressed: () { - acceptRemoveRequest(result.iD, 4, context); - }, - )) - ], - )); - }).toList()) - ]) - ], - )); - }, - separatorBuilder: (context, index) => SizedBox(height: 14), - itemCount: 1); - } - }, - ), + return ListView( + children: [ + SizedBox(height: 21), + pendingRequestView(), + SizedBox(height: 12), + sentRequestView(), + SizedBox(height: 12), + approvedRequestView(), + ], + ); + } + + Widget requestDecoratedContainerWithExpandable(String title, List columns, List rows) { + return AppExpandableNotifier( + title: title, + bodyWidget: Container( + margin: EdgeInsets.only(left: 21, right: 21, bottom: 21), + padding: EdgeInsets.only(top: 12, bottom: 12, left: 14, right: 14), + decoration: BoxDecoration( + borderRadius: BorderRadius.all( + Radius.circular(10.0), + ), + border: Border.all(width: 1, color: CustomColors.backgroudGreyColor), + boxShadow: [ + BoxShadow( + color: Color(0xff000000).withOpacity(.05), + blurRadius: 27, + offset: Offset(0, -3), ), + ], + color: Colors.white), + child: Column(children: [ + Row(children: columns), + SizedBox(height: 6), + Divider(color: CustomColors.textDarkColor, height: 1, thickness: 1), + SizedBox(height: 8), + ListView.separated( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + padding: EdgeInsets.zero, + itemBuilder: (cxt, index) => rows[index], + separatorBuilder: (cxt, index) => SizedBox(height: 12), + itemCount: rows.length), + ]), + ), + ); + } + + Widget pendingRequestView() { + return requestDecoratedContainerWithExpandable( + TranslationBase.of(context).userViewRequest, + [ + Expanded(flex: 3, child: columnText(TranslationBase.of(context).name)), + Expanded(flex: 1, child: columnText(TranslationBase.of(context).allow)), + Expanded(flex: 1, child: columnText(TranslationBase.of(context).reject)), + ], + pendingRecordsList.map((result) { + return pendingItemView(result); + }).toList()); + } + + Widget pendingItemView(GetAllSharedRecordsByStatusList result) { + return Row( + children: [ + Expanded(flex: 3, child: rowText(result.patientName)), + Expanded( + flex: 1, + child: Align( + alignment: Alignment.centerLeft, + child: InkWell( + child: SvgPicture.asset("assets/images/new-design/allow.svg", height: 17), + onTap: () { + acceptRemoveRequest(result.iD, 3, context); + }, ), - SizedBox(height: 15), - FractionallySizedBox( - widthFactor: 1.0, - child: AppExpandableNotifier( - title: TranslationBase.of(context).sentRequest, - bodyWidget: FutureBuilder( - future: getSentRequest(), // async work - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.waiting: - return SizedBox(); - default: - if (snapshot.hasError) - return Padding(padding: EdgeInsets.all(10), child: Text(TranslationBase.of(context).noDataAvailable)); - else - return ListView.separated( - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - padding: EdgeInsets.only(bottom: 14, top: 14, left: 21, right: 21), - itemBuilder: (context, _index) { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(10.0), - ), - border: Border.all(width: 1, color: Color(0xffEFEFEF)), - boxShadow: [ - BoxShadow( - color: Color(0xff000000).withOpacity(.05), - //spreadRadius: 5, - blurRadius: 27, - offset: Offset(0, -3), - ), - ], - color: Colors.white), - child: Column( - children: [ - 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).status, fontWeight: FontWeight.w600)) - ])), - Padding( - padding: const EdgeInsets.only(left: 10.0, right: 10.0), - child: Divider(color: Colors.black, height: 1.5, thickness: 1.5), - ), - Column( - children: snapshot.data.getAllSharedRecordsByStatusList.map((result) { - return Padding( - padding: EdgeInsets.all(10), - child: Row( - children: [ - Expanded( - flex: 3, - child: Texts( - result.patientName, - fontWeight: FontWeight.w600, - fontSize: 12, - )), - Expanded( - flex: 1, - child: Card( - // shape: cardRadius(10), - color: result.status == 3 ? Color(0xff349745) : Color(0xffD02127), - child: Padding( - padding: EdgeInsets.all(5), - child: AppText( - result.statusDescription != null ? result.statusDescription : "", - color: Colors.white, - textAlign: TextAlign.center, - fontSize: 12, - ), - ), - ), - ), - ], - )); - }).toList(), - ) - ], - )); - }, - separatorBuilder: (context, index) => SizedBox(height: 14), - itemCount: 1, - ); - } - }))), - SizedBox( - height: 15, + ), + ), + Expanded( + flex: 1, + child: Align( + alignment: Alignment.centerLeft, + child: InkWell( + child: SvgPicture.asset("assets/images/new-design/reject.svg", height: 17), + onTap: () { + acceptRemoveRequest(result.iD, 4, context); + }, ), - FractionallySizedBox( - widthFactor: 1.0, - child: AppExpandableNotifier( - title: TranslationBase.of(context).userView, - bodyWidget: FutureBuilder( - future: getUserViewRequest(), // async work - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.waiting: - return Padding(padding: EdgeInsets.only(top: 50), child: Text('')); - default: - if (snapshot.hasError) - return Padding(padding: EdgeInsets.all(10), child: Text(TranslationBase.of(context).noDataAvailable)); - else - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(10.0), - ), - border: Border.all(width: 1, color: Color(0xffEFEFEF)), - boxShadow: [ - BoxShadow( - color: Color(0xff000000).withOpacity(.05), - //spreadRadius: 5, - blurRadius: 27, - offset: Offset(0, -3), - ), - ], - color: Colors.white), - child: Column( - children: [ - Column(children: [ - 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).delete, - fontWeight: FontWeight.w600, - textAlign: TextAlign.center, - )), - ])), - Padding( - padding: const EdgeInsets.only(left: 10.0, right: 10.0), - child: Divider(color: Colors.black, height: 1.5, thickness: 1.5), - ), - Column( - children: familyFileProvider.allSharedRecordsByStatusResponse.getAllSharedRecordsByStatusList.map((result) { - return Padding( - padding: EdgeInsets.all(10), - child: Row( - children: [ - Expanded( - flex: 3, - child: Texts( - result.patientName, - fontWeight: FontWeight.w600, - fontSize: 12, - )), - Expanded( - flex: 1, - child: IconButton( - icon: Icon( - Icons.delete, - color: Colors.red, - ), - onPressed: () { - deactivateRequest(result.iD, 5, context); - }, - )), - ], - )); - }).toList()) - ]) - ], - )); - } - }))) - ], + ), ), - ), + ], + ); + } + + Widget sentRequestView() { + return requestDecoratedContainerWithExpandable( + TranslationBase.of(context).sentRequest, + [ + Expanded(flex: 4, child: columnText(TranslationBase.of(context).name)), + Expanded(flex: 2, child: columnText(TranslationBase.of(context).status)), + ], + sentRecordsList.map((result) { + return sentItemView(result); + }).toList()); + } + + Widget sentItemView(GetAllSharedRecordsByStatusList result) { + return Row( + children: [ + Expanded(flex: 2, child: rowText(result.patientName)), + Expanded( + flex: 1, + child: Row( + children: [ + Container( + padding: EdgeInsets.only(top: 3, bottom: 3, left: 8, right: 8), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(50), + color: result.status == 3 ? Color(0xff349745) : Color(0xffD02127), + ), + child: Text( + result.statusDescription != null ? result.statusDescription : "", + style: TextStyle( + fontSize: 10, + color: Colors.white, + letterSpacing: -0.4, + fontWeight: FontWeight.w600, + ), + ), + ), + ], + ), + ), + ], + ); + } + + Widget approvedRequestView() { + return requestDecoratedContainerWithExpandable( + TranslationBase.of(context).userView, + [ + Expanded(flex: 4, child: columnText(TranslationBase.of(context).name)), + Expanded(flex: 2, child: columnText(TranslationBase.of(context).delete)), + ], + approvedRecordsList.map((result) { + return approvedItemView(result); + }).toList()); + } + + Widget approvedItemView(GetAllSharedRecordsByStatusList result) { + return Row( + children: [ + Expanded(flex: 4, child: rowText(result.patientName)), + Expanded( + flex: 2, + child: Align( + alignment: Alignment.centerLeft, + child: InkWell( + child: Icon( + Icons.delete, + color: Colors.red, + size: 12, + ), + onTap: () { + acceptRemoveRequest(result.iD, 4, context); + }, + ), + ), + ), + ], ); } @@ -574,24 +425,6 @@ 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))); - } else { - return familyFileProvider.getSharedRecordByStatus(); - } - } - - Future getUserViewRequest() async { - var user = await sharedPref.getObject(USER_PROFILE); - return familyFileProvider.getUserViewRequest(user['PatientID']); - } - - Future getSentRequest() async { - // var user = await sharedPref.getObject(USER_PROFILE); - return familyFileProvider.getUserSentRequest(); - } - deleteFamily(family, context) { showDialog( context: context, @@ -629,7 +462,7 @@ class _MyFamily extends State with TickerProviderStateMixin { // Utils.showProgressDialog(context); this.familyFileProvider.silentLoggin(user is AuthenticatedUser ? null : user, mainUser: user is AuthenticatedUser).then((value) => loginAfter(value, context)).catchError((err) { - print(err); + print("err:$err"); AppToast.showErrorToast(message: err.toString()); Navigator.of(context).pop(); }); @@ -662,28 +495,22 @@ class _MyFamily extends State with TickerProviderStateMixin { Provider.of(AppGlobal.context, listen: false).user = authenticatedUserObject.user; Provider.of(AppGlobal.context, listen: false).setUser(authenticatedUserObject.user); - appointmentRateViewModel - .getIsLastAppointmentRatedList() - .then((value) => { - getToDoCount(), - GifLoaderDialogUtils.hideDialog(context), - if (appointmentRateViewModel.isHaveAppointmentNotRate) - { - Navigator.pushAndRemoveUntil( - context, - FadePage( - page: RateAppointmentDoctor(), - ), - (r) => false) - } - else - {Navigator.pushAndRemoveUntil(AppGlobal.context, MaterialPageRoute(builder: (context) => LandingPage()), (Route r) => false)} - }) - .catchError((err) { - print(err); - // Utils.hideProgressDialog(); + try { + // await appointmentRateViewModel.getIsLastAppointmentRatedList(); + await getToDoCount(); + if (appointmentRateViewModel.isHaveAppointmentNotRate) { + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: RateAppointmentDoctor(), + ), + (r) => false); + } else { + Navigator.pushAndRemoveUntil(AppGlobal.context, MaterialPageRoute(builder: (context) => LandingPage()), (Route r) => false); + } + } catch (er) { GifLoaderDialogUtils.hideDialog(context); - }); + } } deactivateRequest(ID, status, context) { @@ -705,24 +532,98 @@ class _MyFamily extends State with TickerProviderStateMixin { checkUserData() async { if (await this.sharedPref.getObject(USER_PROFILE) != null) { var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE)); - var data2 = AuthenticatedUser.fromJson(await this.sharedPref.getObject(MAIN_USER)); + await getFamilyFiles(); setState(() { this.user = data; }); } } - getToDoCount() { + List familySharedRecordsList = []; + List pendingRecordsList = []; + List approvedRecordsList = []; + List sentRecordsList = []; + + Future getFamilyFiles() async { + GetAllSharedRecordsByStatusResponse familySharedRecords; + if (await sharedPref.getObject(FAMILY_FILE) != null) { + familySharedRecords = GetAllSharedRecordsByStatusResponse.fromJson(await sharedPref.getObject(FAMILY_FILE)); + } + GifLoaderDialogUtils.showMyDialog(context); + try { + if (familySharedRecords == null) { + familySharedRecords = await familyFileProvider.getSharedRecordByStatus(); + } + familySharedRecords.getAllSharedRecordsByStatusList.forEach((element) { + if (element.status == 3) { + familySharedRecordsList.add(element); + } + sentRecordsList.add(element); + }); + + GetAllSharedRecordsByStatusResponse pendingAndApprovedRecords = await getUserViewRequest(); + pendingAndApprovedRecords.getAllSharedRecordsByStatusList.forEach((element) { + print(element.toJson()); + if (element.status == 2) { + pendingRecordsList.add(element); + } else if (element.status == 3) { + approvedRecordsList.add(element); + } + }); + } catch (ex) { + familySharedRecords = GetAllSharedRecordsByStatusResponse(getAllSharedRecordsByStatusList: []); + } + GifLoaderDialogUtils.hideDialog(context); + } + + Future getUserViewRequest() async { + var user = await sharedPref.getObject(USER_PROFILE); + return familyFileProvider.getUserViewRequest(user['PatientID']); + } + + Future getSentRequest() async { + // var user = await sharedPref.getObject(USER_PROFILE); + return familyFileProvider.getUserSentRequest(); + } + + getToDoCount() async { toDoProvider.setState(0, true, toDoProvider.notificationsCount); - ClinicListService service = new ClinicListService(); - service.getActiveAppointmentNo(context).then((res) { + ClinicListService service = ClinicListService(); + try { + var res = await service.getActiveAppointmentNo(context); print(res['AppointmentActiveNumber']); if (res['MessageStatus'] == 1 && res['AppointmentActiveNumber'] != null) { toDoProvider.setState(res['AppointmentActiveNumber'], true, toDoProvider.notificationsCount); } else {} - }).catchError((err) { - print(err); - }); + } catch (ex) { + print("getToDoCount:$ex"); + } + } + + Widget columnText(String title) { + return Text( + title, + textAlign: TextAlign.left, + style: TextStyle( + fontSize: 12, + color: CustomColors.textDarkColor, + letterSpacing: -0.48, + fontWeight: FontWeight.w600, + ), + ); + } + + Widget rowText(String title) { + return Text( + title, + textAlign: TextAlign.left, + style: TextStyle( + fontSize: 10, + color: CustomColors.textColor, + letterSpacing: -0.4, + fontWeight: FontWeight.w600, + ), + ); } } diff --git a/lib/pages/landing/fragments/home_page_fragment2.dart b/lib/pages/landing/fragments/home_page_fragment2.dart index 2ddf9694..95e88ed5 100644 --- a/lib/pages/landing/fragments/home_page_fragment2.dart +++ b/lib/pages/landing/fragments/home_page_fragment2.dart @@ -70,8 +70,10 @@ class _HomePageFragment2State extends State { @override Widget build(BuildContext context) { projectViewModel = Provider.of(context); + print(""); initialiseHmgServices(false); var appoCountProvider = Provider.of(context); + var userProvider = Provider.of(context); List myMedicalList = Utils.myMedicalListHomePage(projectViewModel: projectViewModel, context: context, count: appoCountProvider.count, isLogin: projectViewModel.isLogin); return Container( width: double.infinity, diff --git a/lib/services/family_files/family_files_provider.dart b/lib/services/family_files/family_files_provider.dart index 2ca4ee8a..af8c61f1 100644 --- a/lib/services/family_files/family_files_provider.dart +++ b/lib/services/family_files/family_files_provider.dart @@ -75,7 +75,7 @@ class FamilyFilesProvider with ChangeNotifier { } else return Future.error("No Data"); } catch (error) { - print(error); + print("errorerror:$error"); return Future.error(error); } } diff --git a/lib/theme/colors.dart b/lib/theme/colors.dart index 6640b442..328af105 100644 --- a/lib/theme/colors.dart +++ b/lib/theme/colors.dart @@ -14,6 +14,7 @@ class CustomColors { static const Color lightGreyColor = Color(0xFFE2E2E2); static const Color devider = Color(0xFFE5E5E5); static const Color darkGreyColor = Color(0xFFC9C9C9); + static const Color textDarkColor = Color(0xFF2E303A); static const Color pharmacyGreyColor = Color(0xFFDBDBDB); static const Color backgroudGreyColor = Color(0xFFEFEFEF); static const Color appBackgroudGreyColor = Color(0xFFF7F7F7); From 1b82146303eb6f0ee7187953dacfd812faaebfaf Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Mon, 21 Mar 2022 11:36:25 +0300 Subject: [PATCH 2/2] my family switch profile on dashboard. --- lib/core/viewModels/base_view_model.dart | 4 ++-- lib/pages/DrawerPages/family/my-family.dart | 15 +++++++-------- .../landing/fragments/home_page_fragment2.dart | 4 ++-- lib/widgets/drawer/app_drawer_widget.dart | 15 +++++++-------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/core/viewModels/base_view_model.dart b/lib/core/viewModels/base_view_model.dart index 46a36c27..98fb0b17 100644 --- a/lib/core/viewModels/base_view_model.dart +++ b/lib/core/viewModels/base_view_model.dart @@ -29,9 +29,9 @@ class BaseViewModel extends ChangeNotifier { if (hasListeners) notifyListeners(); } - setUser(AuthenticatedUser user, {bool notify = true}) { + setUser(AuthenticatedUser user) { this.user = user; - if (notify) notifyListeners(); + notifyListeners(); } BaseViewModel() { diff --git a/lib/pages/DrawerPages/family/my-family.dart b/lib/pages/DrawerPages/family/my-family.dart index daf7a650..f83945f8 100644 --- a/lib/pages/DrawerPages/family/my-family.dart +++ b/lib/pages/DrawerPages/family/my-family.dart @@ -484,16 +484,15 @@ class _MyFamily extends State with TickerProviderStateMixin { this.sharedPref.setString(BLOOD_TYPE, bloodType); this.sharedPref.setString(APP_LANGUAGE, currentLang); this.sharedPref.setInt(LAST_LOGIN, loginType); - this.sharedPref.setObject(MAIN_USER, mainUser); - this.sharedPref.setObject(USER_PROFILE, result.list); - this.sharedPref.setObject(FAMILY_FILE, familyFile); - this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); - this.sharedPref.setString(TOKEN, result.authenticationTokenID); + await this.sharedPref.setObject(MAIN_USER, mainUser); + await this.sharedPref.setObject(USER_PROFILE, result.list); + await this.sharedPref.setObject(FAMILY_FILE, familyFile); + await this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); + await this.sharedPref.setString(TOKEN, result.authenticationTokenID); _vitalSignService.heightCm = ""; _vitalSignService.weightKg = ""; - await authenticatedUserObject.getUser(getUser: true); - Provider.of(AppGlobal.context, listen: false).user = authenticatedUserObject.user; - Provider.of(AppGlobal.context, listen: false).setUser(authenticatedUserObject.user); + Provider.of(AppGlobal.context, listen: false).user = result.list; + Provider.of(AppGlobal.context, listen: false).setUser(result.list); try { // await appointmentRateViewModel.getIsLastAppointmentRatedList(); diff --git a/lib/pages/landing/fragments/home_page_fragment2.dart b/lib/pages/landing/fragments/home_page_fragment2.dart index 95e88ed5..c3b7f0ca 100644 --- a/lib/pages/landing/fragments/home_page_fragment2.dart +++ b/lib/pages/landing/fragments/home_page_fragment2.dart @@ -90,8 +90,8 @@ class _HomePageFragment2State extends State { }, child: LoggedSliderView( projectViewModel, - new SliderData(TranslationBase.of(context).fileno + ": " + projectViewModel.user.patientID.toString(), projectViewModel.user.firstName + ' ' + projectViewModel.user.lastName, - "", bannerColor[0].darkColor, bannerColor[0].lightColor), + new SliderData(TranslationBase.of(context).fileno + ": " + (projectViewModel.user?.patientID?.toString() ?? ""), + projectViewModel.user.firstName + ' ' + (projectViewModel.user?.lastName ?? ""), "", bannerColor[0].darkColor, bannerColor[0].lightColor), widget.model, ), ), diff --git a/lib/widgets/drawer/app_drawer_widget.dart b/lib/widgets/drawer/app_drawer_widget.dart index 5375e97d..1cf83827 100644 --- a/lib/widgets/drawer/app_drawer_widget.dart +++ b/lib/widgets/drawer/app_drawer_widget.dart @@ -589,15 +589,14 @@ class _AppDrawerState extends State { this.sharedPref.setString(APP_LANGUAGE, currentLang); this.sharedPref.setString(BLOOD_TYPE, bloodType); this.sharedPref.setInt(LAST_LOGIN, loginType); - this.sharedPref.setObject(MAIN_USER, mainUser); - this.sharedPref.setObject(USER_PROFILE, result.list); - this.sharedPref.setObject(FAMILY_FILE, familyFile); - this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); - this.sharedPref.setString(TOKEN, result.authenticationTokenID); + await this.sharedPref.setObject(MAIN_USER, mainUser); + await this.sharedPref.setObject(USER_PROFILE, result.list); + await this.sharedPref.setObject(FAMILY_FILE, familyFile); + await this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); + await this.sharedPref.setString(TOKEN, result.authenticationTokenID); // Navigator.of(context).pop(); - 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 = result.list; + Provider.of(context, listen: false).setUser(result.list); // await pharmacyModuleViewModel.generatePharmacyToken(); _vitalSignService.heightCm = ""; _vitalSignService.weightKg = "";