Refactor provider initialization to load only essential providers at startup. Introduce TabNavigationService for managing tab state and update screens to respond to tab changes. Clean up view models and navigation logic for improved performance and maintainability.
This commit is contained in:
@@ -5,11 +5,9 @@ import 'package:tm_app/core/routes/app_shell/desktop_shell_page.dart';
|
||||
import 'package:tm_app/core/routes/app_shell/mobile_shell_page.dart';
|
||||
import 'package:tm_app/core/routes/app_shell/tablet_shell_page.dart';
|
||||
import 'package:tm_app/data/services/notification_check_service.dart';
|
||||
import 'package:tm_app/view_models/home_view_model.dart';
|
||||
import 'package:tm_app/view_models/tenders_view_model.dart';
|
||||
import 'package:tm_app/views/shared/responsive_builder.dart';
|
||||
|
||||
import '../../../view_models/notification_view_model.dart';
|
||||
import '../../services/tab_navigation_service.dart';
|
||||
|
||||
class AppShellScreen extends StatefulWidget {
|
||||
const AppShellScreen({required this.navigationShell, super.key});
|
||||
@@ -35,24 +33,14 @@ class _AppShellScreenState extends State<AppShellScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
// Navigate first
|
||||
// Navigate to the selected branch
|
||||
widget.navigationShell.goBranch(
|
||||
index,
|
||||
initialLocation: index == widget.navigationShell.currentIndex,
|
||||
);
|
||||
|
||||
// Then trigger data loading after navigation is complete
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (index == 0) {
|
||||
context.read<HomeViewModel>().init();
|
||||
}
|
||||
if (index == 1) {
|
||||
context.read<TendersViewModel>().init(context);
|
||||
}
|
||||
if (index == 3) {
|
||||
context.read<NotificationViewModel>().init();
|
||||
}
|
||||
});
|
||||
// Notify that tab has changed so screens can refresh
|
||||
context.read<TabNavigationService>().onTabSelected(index);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user