From dc6b71a4ca84a00e40e6b0a3accd79c78931718e Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 10 Aug 2026 20:52:58 +0300 Subject: [PATCH] Tab changed to arrived in my appointments --- .../my_appointments_view_model.dart | 24 +++++++++++++++++-- .../appointments/my_appointments_page.dart | 3 +-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/features/my_appointments/my_appointments_view_model.dart b/lib/features/my_appointments/my_appointments_view_model.dart index 293dec71..57421ee2 100644 --- a/lib/features/my_appointments/my_appointments_view_model.dart +++ b/lib/features/my_appointments/my_appointments_view_model.dart @@ -363,11 +363,25 @@ class MyAppointmentsViewModel extends ChangeNotifier { notifyListeners(); } + changeTabToArrived() { + if (patientUpcomingAppointmentsHistoryList.isEmpty && patientArrivedAppointmentsHistoryList.isNotEmpty && selectedTabIndex == 0) { + selectedTabIndex = 1; + updateListWRTTab(1); + notifyListeners(); + } + } + /// Loads full arrived appointments list if not already loaded /// This is called when navigating to My Appointments page from landing page Future loadFullArrivedAppointmentsIfNeeded({Function(dynamic)? onSuccess, Function(String)? onError}) async { // Skip if already loaded if (isFullArrivedAppointmentsLoaded) { + // Auto-switch to Arrived tab if no upcoming appointments (even when data is already loaded) + if (patientUpcomingAppointmentsHistoryList.isEmpty && patientArrivedAppointmentsHistoryList.isNotEmpty && selectedTabIndex == 0) { + selectedTabIndex = 1; + updateListWRTTab(1); + notifyListeners(); + } return; } @@ -394,8 +408,14 @@ class MyAppointmentsViewModel extends ChangeNotifier { isMyAppointmentsLoading = false; - // Update filtered list based on current tab - updateListWRTTab(selectedTabIndex); + // Auto-switch to Arrived tab if no upcoming appointments + if (patientUpcomingAppointmentsHistoryList.isEmpty && patientArrivedAppointmentsHistoryList.isNotEmpty && selectedTabIndex == 0) { + selectedTabIndex = 1; + updateListWRTTab(1); + } else { + // Update filtered list based on current tab + updateListWRTTab(selectedTabIndex); + } notifyListeners(); if (onSuccess != null) { diff --git a/lib/presentation/appointments/my_appointments_page.dart b/lib/presentation/appointments/my_appointments_page.dart index 9bd9b61d..82696f69 100644 --- a/lib/presentation/appointments/my_appointments_page.dart +++ b/lib/presentation/appointments/my_appointments_page.dart @@ -47,8 +47,7 @@ class _MyAppointmentsPageState extends State { myAppointmentsViewModel.initAppointmentsViewModel(); myAppointmentsViewModel.getPatientAppointments(true, false, isForTimeLine: false); } - // Load full arrived appointments if not already loaded - // myAppointmentsViewModel.loadFullArrivedAppointmentsIfNeeded(); + myAppointmentsViewModel.changeTabToArrived(); }); super.initState(); }