From 53d7d68012c328f95839bee1a67d773cf65e1550 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Mon, 16 Aug 2021 15:17:04 +0300 Subject: [PATCH] add badge on bottom bar in order to show number of un replied msg --- lib/config/config.dart | 1 + .../service/home/doctor_reply_service.dart | 19 ++++- lib/core/viewModel/dashboard_view_model.dart | 15 ++++ .../viewModel/doctor_replay_view_model.dart | 6 +- lib/screens/home/home_screen.dart | 1 + lib/widgets/shared/bottom_nav_bar.dart | 1 + .../shared/bottom_navigation_item.dart | 71 ++++++++++++++----- pubspec.yaml | 3 + 8 files changed, 95 insertions(+), 22 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index bf398791..1173941d 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -235,6 +235,7 @@ const GET_SICK_LEAVE_DOCTOR_APP = "Services/DoctorApplication.svc/REST/GetAllSic const ADD_PATIENT_TO_DOCTOR = "LiveCareApi/DoctorApp/AssignPatientToDoctor"; const REMOVE_PATIENT_FROM_DOCTOR = "LiveCareApi/DoctorApp/BackPatientToQueue"; const CREATE_DOCTOR_RESPONSE = "Services/DoctorApplication.svc/REST/CreateDoctorResponse"; +const GET_DOCTOR_NOT_REPLIED_COUNTS = "Services/DoctorApplication.svc/REST/DoctorApp_GetDoctorNotRepliedCounts"; var selectedPatientType = 1; diff --git a/lib/core/service/home/doctor_reply_service.dart b/lib/core/service/home/doctor_reply_service.dart index 82bb67e2..f8008e0e 100644 --- a/lib/core/service/home/doctor_reply_service.dart +++ b/lib/core/service/home/doctor_reply_service.dart @@ -16,6 +16,7 @@ class DoctorReplyService extends BaseService { RequestDoctorReply _requestDoctorReply = RequestDoctorReply(); List _listMyReferralPatientModel = []; List get listMyReferralPatientModel => _listMyReferralPatientModel; + int notRepliedCount = 0; Future getDoctorReply() async { hasError = false; @@ -39,7 +40,23 @@ class DoctorReplyService extends BaseService { CREATE_DOCTOR_RESPONSE, body: createDoctorResponseModel.toJson(), onSuccess: (dynamic body, int statusCode) { - print("succsss"); + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + ); + } + + + Future getNotRepliedCount() async { + hasError = false; + await baseAppClient.post( + GET_DOCTOR_NOT_REPLIED_COUNTS, + body: {}, + onSuccess: (dynamic body + , int statusCode) { + notRepliedCount = body["DoctorNotRepliedCounts"]; }, onFailure: (String error, int statusCode) { hasError = true; diff --git a/lib/core/viewModel/dashboard_view_model.dart b/lib/core/viewModel/dashboard_view_model.dart index 8346e33d..946f2177 100644 --- a/lib/core/viewModel/dashboard_view_model.dart +++ b/lib/core/viewModel/dashboard_view_model.dart @@ -2,6 +2,7 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/service/home/dasboard_service.dart'; +import 'package:doctor_app_flutter/core/service/home/doctor_reply_service.dart'; import 'package:doctor_app_flutter/core/service/special_clinics/special_clinic_service.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; @@ -17,6 +18,7 @@ class DashboardViewModel extends BaseViewModel { final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); DashboardService _dashboardService = locator(); SpecialClinicsService _specialClinicsService = locator(); + DoctorReplyService _doctorReplyService = locator(); List get dashboardItemsList => _dashboardService.dashboardItemsList; @@ -24,6 +26,7 @@ class DashboardViewModel extends BaseViewModel { bool get hasVirtualClinic => _dashboardService.hasVirtualClinic; String get sServiceID => _dashboardService.sServiceID; + int get notRepliedCount => _doctorReplyService.notRepliedCount; List get specialClinicalCareList => _specialClinicsService.specialClinicalCareList; @@ -114,4 +117,16 @@ class DashboardViewModel extends BaseViewModel { return special; } + + + Future getNotRepliedCount() async { + setState(ViewState.Busy); + await getDoctorProfile(); + await _doctorReplyService.getNotRepliedCount(); + if (_doctorReplyService.hasError) { + error = _doctorReplyService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } } diff --git a/lib/core/viewModel/doctor_replay_view_model.dart b/lib/core/viewModel/doctor_replay_view_model.dart index c6eab29c..7ed0acc4 100644 --- a/lib/core/viewModel/doctor_replay_view_model.dart +++ b/lib/core/viewModel/doctor_replay_view_model.dart @@ -23,7 +23,6 @@ class DoctorReplayViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future createDoctorResponse( String response, ListGtMyPatientsQuestions model) async { await getDoctorProfile(); @@ -41,7 +40,10 @@ class DoctorReplayViewModel extends BaseViewModel { if (_doctorReplyService.hasError) { error = _doctorReplyService.error; setState(ViewState.ErrorLocal); - } else + } else { setState(ViewState.Idle); + _doctorReplyService.getNotRepliedCount(); + + } } } diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 42f8e7f3..795367fa 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -72,6 +72,7 @@ class _HomeScreenState extends State { await model.getDoctorProfile(isGetProfile: true); await model.checkDoctorHasLiveCare(); await model.getSpecialClinicalCareList(); + await model.getNotRepliedCount(); }, builder: (_, model, w) => AppScaffold( baseViewModel: model, diff --git a/lib/widgets/shared/bottom_nav_bar.dart b/lib/widgets/shared/bottom_nav_bar.dart index dd64958a..be6a15f6 100644 --- a/lib/widgets/shared/bottom_nav_bar.dart +++ b/lib/widgets/shared/bottom_nav_bar.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/core/viewModel/doctor_replay_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:flutter/cupertino.dart'; diff --git a/lib/widgets/shared/bottom_navigation_item.dart b/lib/widgets/shared/bottom_navigation_item.dart index e69ff690..6540c060 100644 --- a/lib/widgets/shared/bottom_navigation_item.dart +++ b/lib/widgets/shared/bottom_navigation_item.dart @@ -1,5 +1,11 @@ +import 'package:badges/badges.dart'; +import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_replay_view_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import '../../locator.dart'; class BottomNavigationItem extends StatelessWidget { final IconData icon; @@ -19,6 +25,8 @@ class BottomNavigationItem extends StatelessWidget { @override Widget build(BuildContext context) { + + DashboardViewModel model = DashboardViewModel(); return Expanded( child: SizedBox( height: 70.0, @@ -28,26 +36,51 @@ class BottomNavigationItem extends StatelessWidget { highlightColor: Colors.transparent, splashColor: Colors.transparent, onTap: () => changeIndex(currentIndex), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox(height: 15,), - Container( - child: Icon(currentIndex == index ? activeIcon : icon, - color: currentIndex == index - ? Color(0xFF333C45) - : Theme.of(context).dividerColor, - size: 22.0), + child: Stack( + alignment: AlignmentDirectional.center, + children: [ + + + Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox(height: 15,), + Container( + child: Icon(currentIndex == index ? activeIcon : icon, + color: currentIndex == index + ? Color(0xFF333C45) + : Theme.of(context).dividerColor, + size: 22.0), + ), + SizedBox(height: 5,), + Expanded( + child: Text( + name, + style: TextStyle( + color: currentIndex == index + ? Theme.of(context).primaryColor + : Theme.of(context).dividerColor, + ), + ), + ), + ], ), - SizedBox(height: 5,), - Expanded( - child: Text( - name, - style: TextStyle( - color: currentIndex == index - ? Theme.of(context).primaryColor - : Theme.of(context).dividerColor, + if(currentIndex == 3) + Positioned( + right: 18.0, + bottom: 40.0, + child: Badge( + toAnimate: false, + position: BadgePosition.topEnd(), + shape: BadgeShape.circle, + badgeColor: Colors.red[800], + borderRadius: BorderRadius.circular(8), + badgeContent: Container( + // padding: EdgeInsets.all(2.0), + child: Text(model.notRepliedCount.toString(), + style: TextStyle( + color: Colors.white, fontSize: 12.0)), ), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index 8582b9cb..cf5ced70 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -96,6 +96,9 @@ dependencies: # Html Editor Enhanced html_editor_enhanced: ^1.3.0 + # Badges + badges: ^1.1.4 + dev_dependencies: flutter_test: sdk: flutter