From 943463b1d9cf904a01f6d550b3ff4087e0788ed3 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Tue, 24 Aug 2021 14:17:36 +0300 Subject: [PATCH 1/2] add pagination to doctor replay --- lib/config/localized_values.dart | 1 + .../service/home/doctor_reply_service.dart | 4 +- .../viewModel/doctor_replay_view_model.dart | 35 +++++---- .../doctor/replay/request_doctor_reply.dart | 26 ++++--- lib/screens/doctor/doctor_repaly_chat.dart | 2 +- lib/screens/doctor/doctor_reply_screen.dart | 72 ++++++++++++++----- lib/util/translations_delegate_base.dart | 1 + pubspec.lock | 6 +- 8 files changed, 101 insertions(+), 46 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 56b3fde8..f3308c58 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -709,5 +709,6 @@ const Map> localizedValues = { "Completed": {"en": "Completed", "ar": "مكتمل"}, "Locked": {"en": "Locked", "ar": "مقفل"}, "textCopiedSuccessfully": {"en": "Text copied successfully", "ar": "تم نسخ النص بنجاح"}, + "seeMore": {"en": "See More ...", "ar": "شاهد المزيد..."}, }; diff --git a/lib/core/service/home/doctor_reply_service.dart b/lib/core/service/home/doctor_reply_service.dart index f8008e0e..cdb45f1b 100644 --- a/lib/core/service/home/doctor_reply_service.dart +++ b/lib/core/service/home/doctor_reply_service.dart @@ -13,15 +13,15 @@ class DoctorReplyService extends BaseService { List _listDoctorWorkingHoursTable = []; - RequestDoctorReply _requestDoctorReply = RequestDoctorReply(); List _listMyReferralPatientModel = []; List get listMyReferralPatientModel => _listMyReferralPatientModel; int notRepliedCount = 0; - Future getDoctorReply() async { + Future getDoctorReply(RequestDoctorReply _requestDoctorReply,{bool clearData = false}) async { hasError = false; await baseAppClient.post(GT_MY_PATIENT_QUESTION, onSuccess: (dynamic response, int statusCode) { + if(clearData) _listDoctorWorkingHoursTable.clear(); response['List_GtMyPatientsQuestions'].forEach((v) { _listDoctorWorkingHoursTable diff --git a/lib/core/viewModel/doctor_replay_view_model.dart b/lib/core/viewModel/doctor_replay_view_model.dart index 7ed0acc4..17607d80 100644 --- a/lib/core/viewModel/doctor_replay_view_model.dart +++ b/lib/core/viewModel/doctor_replay_view_model.dart @@ -2,6 +2,7 @@ import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/service/home/doctor_reply_service.dart'; import 'package:doctor_app_flutter/models/doctor/list_gt_my_patients_question_model.dart'; import 'package:doctor_app_flutter/models/doctor/replay/request_create_doctor_response.dart'; +import 'package:doctor_app_flutter/models/doctor/replay/request_doctor_reply.dart'; import '../../locator.dart'; import 'base_view_model.dart'; @@ -12,13 +13,25 @@ class DoctorReplayViewModel extends BaseViewModel { List get listDoctorWorkingHoursTable => _doctorReplyService.listDoctorWorkingHoursTable; - Future getDoctorReply() async { - setState(ViewState.Busy); + Future getDoctorReply( + {int pageSize = 10, int pageIndex = 1, bool isLocalBusy = true}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } await getDoctorProfile(); - await _doctorReplyService.getDoctorReply(); + RequestDoctorReply _requestDoctorReply = + RequestDoctorReply(pageIndex: pageIndex, pageSize: pageSize); + + await _doctorReplyService.getDoctorReply(_requestDoctorReply, clearData:!isLocalBusy ); if (_doctorReplyService.hasError) { error = _doctorReplyService.error; - setState(ViewState.Error); + if (isLocalBusy) { + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Error); + } } else setState(ViewState.Idle); } @@ -28,13 +41,12 @@ class DoctorReplayViewModel extends BaseViewModel { await getDoctorProfile(); CreateDoctorResponseModel createDoctorResponseModel = CreateDoctorResponseModel( - transactionNo: model.transactionNo.toString(), - doctorResponse: response, - infoStatus: 6, - createdBy:this.doctorProfile.doctorID, - infoEnteredBy: this.doctorProfile.doctorID, - setupID:"010266" - ); + transactionNo: model.transactionNo.toString(), + doctorResponse: response, + infoStatus: 6, + createdBy: this.doctorProfile.doctorID, + infoEnteredBy: this.doctorProfile.doctorID, + setupID: "010266"); setState(ViewState.BusyLocal); await _doctorReplyService.createDoctorResponse(createDoctorResponseModel); if (_doctorReplyService.hasError) { @@ -43,7 +55,6 @@ class DoctorReplayViewModel extends BaseViewModel { } else { setState(ViewState.Idle); _doctorReplyService.getNotRepliedCount(); - } } } diff --git a/lib/models/doctor/replay/request_doctor_reply.dart b/lib/models/doctor/replay/request_doctor_reply.dart index 707336d6..1c3948cb 100644 --- a/lib/models/doctor/replay/request_doctor_reply.dart +++ b/lib/models/doctor/replay/request_doctor_reply.dart @@ -13,20 +13,24 @@ class RequestDoctorReply { String sessionID; bool isLoginForDoctorApp; bool patientOutSA; + int pageIndex; + int pageSize; RequestDoctorReply( - {this.projectID , - this.doctorID , - this.transactionNo = TRANSACTION_NO , - this.languageID , - this.stamp , + {this.projectID, + this.doctorID, + this.transactionNo = TRANSACTION_NO, + this.languageID, + this.stamp, this.iPAdress, - this.versionID , + this.versionID, this.channel, - this.tokenID , + this.tokenID, this.sessionID, - this.isLoginForDoctorApp , - this.patientOutSA }); + this.isLoginForDoctorApp, + this.patientOutSA, + this.pageIndex, + this.pageSize}); RequestDoctorReply.fromJson(Map json) { projectID = json['ProjectID']; @@ -41,6 +45,8 @@ class RequestDoctorReply { sessionID = json['SessionID']; isLoginForDoctorApp = json['IsLoginForDoctorApp']; patientOutSA = json['PatientOutSA']; + pageIndex = json['PageIndex']; + pageSize = json['PageSize']; } Map toJson() { @@ -57,6 +63,8 @@ class RequestDoctorReply { data['SessionID'] = this.sessionID; data['IsLoginForDoctorApp'] = this.isLoginForDoctorApp; data['PatientOutSA'] = this.patientOutSA; + data['PageIndex'] = this.pageIndex; + data['PageSize'] = this.pageSize; return data; } } diff --git a/lib/screens/doctor/doctor_repaly_chat.dart b/lib/screens/doctor/doctor_repaly_chat.dart index c3b58806..935dbf7c 100644 --- a/lib/screens/doctor/doctor_repaly_chat.dart +++ b/lib/screens/doctor/doctor_repaly_chat.dart @@ -370,7 +370,7 @@ class DoctorReplayChat extends StatelessWidget { Helpers.showErrorToast(previousModel.error); } else { DrAppToastMsg.showSuccesToast("Thank you for your replay "); - await previousModel.getDoctorReply(); + await previousModel.getDoctorReply(isLocalBusy: false); Navigator.pop(context); } GifLoaderDialogUtils.hideDialog(context); diff --git a/lib/screens/doctor/doctor_reply_screen.dart b/lib/screens/doctor/doctor_reply_screen.dart index b318f6a4..988ddef7 100644 --- a/lib/screens/doctor/doctor_reply_screen.dart +++ b/lib/screens/doctor/doctor_reply_screen.dart @@ -1,10 +1,15 @@ +import 'package:doctor_app_flutter/config/size_config.dart'; +import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/viewModel/doctor_replay_view_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/doctor/doctor_repaly_chat.dart'; +import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/doctor/doctor_reply_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/errors/dr_app_embedded_error.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -15,21 +20,27 @@ import 'package:flutter/material.dart'; *@return: *@desc: Doctor Reply Screen display data from GtMyPatientsQuestions service */ -class DoctorReplyScreen extends StatelessWidget { - +class DoctorReplyScreen extends StatefulWidget { final Function changeCurrentTab; const DoctorReplyScreen({Key key, this.changeCurrentTab}) : super(key: key); + @override + _DoctorReplyScreenState createState() => _DoctorReplyScreenState(); +} + +class _DoctorReplyScreenState extends State { + int pageIndex = 1; + @override Widget build(BuildContext context) { return BaseView( onModelReady: (model) { - model.getDoctorReply(); + model.getDoctorReply(isLocalBusy: false); }, builder: (_, model, w) => WillPopScope( - onWillPop: ()async{ - changeCurrentTab(); + onWillPop: () async { + widget.changeCurrentTab(); return false; }, child: AppScaffold( @@ -45,22 +56,46 @@ class DoctorReplyScreen extends StatelessWidget { Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: - model.listDoctorWorkingHoursTable.map((reply) { + children: model.listDoctorWorkingHoursTable.map( + (reply) { return InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => - DoctorReplayChat( - reply: reply, - previousModel: model, - ), settings: RouteSettings(name: 'DoctorReplayChat'),)); - }, + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => + DoctorReplayChat( + reply: reply, + previousModel: model, + ), + settings: + RouteSettings(name: 'DoctorReplayChat'), + )); + }, child: DoctorReplyWidget(reply: reply), ); - }).toList(), + }).toList() + ..add(InkWell( + onTap: () async { + setState(() { + pageIndex++; + }); + GifLoaderDialogUtils.showMyDialog(context); + await model.getDoctorReply(pageIndex: pageIndex); + if (model.state == ViewState.ErrorLocal) { + GifLoaderDialogUtils.hideDialog(context); + + Helpers.showErrorToast(model.error); + } else + GifLoaderDialogUtils.hideDialog(context); + }, + child: Center( + child: Container( + padding: EdgeInsets.all(20), + child: AppText("${TranslationBase.of(context).seeMore}", fontSize: SizeConfig.getTextMultiplierBasedOnWidth()*4,), + ), + ), + )), ) ], ), @@ -68,6 +103,5 @@ class DoctorReplyScreen extends StatelessWidget { ), ), ); - } } diff --git a/lib/util/translations_delegate_base.dart b/lib/util/translations_delegate_base.dart index e104a01e..afda54eb 100644 --- a/lib/util/translations_delegate_base.dart +++ b/lib/util/translations_delegate_base.dart @@ -1371,6 +1371,7 @@ class TranslationBase { String get summeryReply => localizedValues['summeryReply'][locale.languageCode]; String get severityValidationError => localizedValues['severityValidationError'][locale.languageCode]; String get textCopiedSuccessfully => localizedValues['textCopiedSuccessfully'][locale.languageCode]; + String get seeMore => localizedValues['seeMore'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate { diff --git a/pubspec.lock b/pubspec.lock index 0229e774..e2215d0c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -664,7 +664,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.4" + version: "1.3.0-nullsafety.3" mime: dependency: transitive description: @@ -956,7 +956,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.2" + version: "1.10.0-nullsafety.1" sticky_headers: dependency: "direct main" description: @@ -1154,5 +1154,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.10.0 <=2.11.0-213.1.beta" + dart: ">=2.10.0 <2.11.0" flutter: ">=1.22.0 <2.0.0" From 64c98ba12825ff6e845c9fd587dbdc6c482efc24 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Tue, 24 Aug 2021 15:48:23 +0300 Subject: [PATCH 2/2] modify pagination to make works on scroll --- lib/screens/doctor/doctor_reply_screen.dart | 97 +++++++++++---------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/lib/screens/doctor/doctor_reply_screen.dart b/lib/screens/doctor/doctor_reply_screen.dart index 988ddef7..9047bb2d 100644 --- a/lib/screens/doctor/doctor_reply_screen.dart +++ b/lib/screens/doctor/doctor_reply_screen.dart @@ -8,6 +8,7 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/doctor/doctor_reply_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart'; import 'package:doctor_app_flutter/widgets/shared/errors/dr_app_embedded_error.dart'; import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:flutter/cupertino.dart'; @@ -49,57 +50,61 @@ class _DoctorReplyScreenState extends State { isShowAppBar: false, body: model.listDoctorWorkingHoursTable.isEmpty ? DrAppEmbeddedError(error: TranslationBase.of(context).noItem) - : Container( - padding: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - child: ListView( - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: model.listDoctorWorkingHoursTable.map( - (reply) { - return InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => - DoctorReplayChat( - reply: reply, - previousModel: model, + : Column( + children: [ + Expanded( + child: Container( + padding: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), + child: NotificationListener( + child: ListView.builder( + scrollDirection: Axis.vertical, + shrinkWrap: true, + + itemBuilder: (BuildContext ctxt, int index) { + return Column( + children: [ + InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => + DoctorReplayChat( + reply: + model.listDoctorWorkingHoursTable[ + index], + previousModel: model, + ), + settings: RouteSettings( + name: 'DoctorReplayChat'), + )); + }, + child: DoctorReplyWidget( + reply: model + .listDoctorWorkingHoursTable[index]), ), - settings: - RouteSettings(name: 'DoctorReplayChat'), - )); - }, - child: DoctorReplyWidget(reply: reply), - ); - }).toList() - ..add(InkWell( - onTap: () async { + if(model.state == ViewState.BusyLocal &&index ==model.listDoctorWorkingHoursTable.length-1) + DrAppCircularProgressIndeicator() + + ], + ); + }), + onNotification: (t) { + if (t is ScrollEndNotification && + model.state != ViewState.BusyLocal) { + print("${model.state}"); setState(() { pageIndex++; }); - GifLoaderDialogUtils.showMyDialog(context); - await model.getDoctorReply(pageIndex: pageIndex); - if (model.state == ViewState.ErrorLocal) { - GifLoaderDialogUtils.hideDialog(context); - - Helpers.showErrorToast(model.error); - } else - GifLoaderDialogUtils.hideDialog(context); - }, - child: Center( - child: Container( - padding: EdgeInsets.all(20), - child: AppText("${TranslationBase.of(context).seeMore}", fontSize: SizeConfig.getTextMultiplierBasedOnWidth()*4,), - ), - ), - )), - ) - ], + model.getDoctorReply(pageIndex: pageIndex); + } + return; + }, + ), + ), ), - ), + ], + ), ), ), );