diff --git a/lib/core/viewModel/dashboard_view_model.dart b/lib/core/viewModel/dashboard_view_model.dart index 68c69ddf..02e540af 100644 --- a/lib/core/viewModel/dashboard_view_model.dart +++ b/lib/core/viewModel/dashboard_view_model.dart @@ -126,7 +126,9 @@ class DashboardViewModel extends BaseViewModel { if (_doctorReplyService.hasError) { error = _doctorReplyService.error; setState(ViewState.ErrorLocal); - } else + } else { + notifyListeners(); setState(ViewState.Idle); + } } } diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 795367fa..42f8e7f3 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -72,7 +72,6 @@ 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 be6a15f6..16988d82 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/dashboard_view_model.dart'; 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'; @@ -9,6 +10,9 @@ import 'bottom_navigation_item.dart'; class BottomNavBar extends StatefulWidget { final ValueChanged changeIndex; final int index; + + DashboardViewModel dashboardViewModel = DashboardViewModel(); + BottomNavBar({Key key, this.changeIndex, this.index}) : super(key: key); @override @@ -25,6 +29,12 @@ class _BottomNavBarState extends State { }); } + @override + void initState() { + widget.dashboardViewModel.getNotRepliedCount(); + super.initState(); + } + @override Widget build(BuildContext context) { return BottomAppBar( @@ -44,6 +54,7 @@ class _BottomNavBarState extends State { index: widget.index, currentIndex: 0, name: TranslationBase.of(context).home, + dashboardViewModel: widget.dashboardViewModel, ), BottomNavigationItem( icon: DoctorApp.schedule_1, @@ -52,6 +63,8 @@ class _BottomNavBarState extends State { index: widget.index, currentIndex: 1, name: TranslationBase.of(context).mySchedule, + dashboardViewModel: widget.dashboardViewModel, + ), BottomNavigationItem( icon: DoctorApp.qr_reader, @@ -60,6 +73,8 @@ class _BottomNavBarState extends State { index: widget.index, currentIndex: 2, name: TranslationBase.of(context).qr, + dashboardViewModel: widget.dashboardViewModel, + ), BottomNavigationItem( icon: DoctorApp.dr_reply_1, @@ -68,6 +83,8 @@ class _BottomNavBarState extends State { index: widget.index, currentIndex: 3, name: TranslationBase.of(context).replay2, + dashboardViewModel: widget.dashboardViewModel, + ), ], ), diff --git a/lib/widgets/shared/bottom_navigation_item.dart b/lib/widgets/shared/bottom_navigation_item.dart index 6ca4d5d6..02b64c78 100644 --- a/lib/widgets/shared/bottom_navigation_item.dart +++ b/lib/widgets/shared/bottom_navigation_item.dart @@ -14,6 +14,9 @@ class BottomNavigationItem extends StatelessWidget { final int index; final int currentIndex; final String name; + final DashboardViewModel dashboardViewModel; + + BottomNavigationItem( {this.icon, @@ -21,12 +24,11 @@ class BottomNavigationItem extends StatelessWidget { this.changeIndex, this.index, this.currentIndex, - this.name}); + this.name, this.dashboardViewModel}); + @override Widget build(BuildContext context) { - - DashboardViewModel model = DashboardViewModel(); return Expanded( child: SizedBox( height: 70.0, @@ -66,7 +68,7 @@ class BottomNavigationItem extends StatelessWidget { ), ], ), - if(currentIndex == 3 && model.notRepliedCount != 0) + if(currentIndex == 3 && dashboardViewModel.notRepliedCount != 0) Positioned( right: 18.0, bottom: 40.0, @@ -78,7 +80,7 @@ class BottomNavigationItem extends StatelessWidget { borderRadius: BorderRadius.circular(8), badgeContent: Container( // padding: EdgeInsets.all(2.0), - child: Text(model.notRepliedCount.toString(), + child: Text(dashboardViewModel.notRepliedCount.toString(), style: TextStyle( color: Colors.white, fontSize: 12.0)), ),