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:
@@ -2,16 +2,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tm_app/core/constants/assets.dart';
|
||||
import 'package:tm_app/core/services/tab_navigation_service.dart';
|
||||
import 'package:tm_app/core/theme/colors.dart';
|
||||
import 'package:tm_app/core/utils/size_config.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/data/services/notification_state_service.dart';
|
||||
import 'package:tm_app/views/home/strings/home_strings.dart';
|
||||
import 'package:tm_app/views/profile/strings/profile_strings.dart';
|
||||
import 'package:tm_app/views/tenders/strings/tenders_strings.dart';
|
||||
|
||||
import '../../core/routes/app_routes.dart';
|
||||
import '../../view_models/notification_view_model.dart';
|
||||
|
||||
class DesktopNavigationWidget extends StatelessWidget {
|
||||
const DesktopNavigationWidget({
|
||||
@@ -45,7 +44,7 @@ class DesktopNavigationWidget extends StatelessWidget {
|
||||
context,
|
||||
() => const HomeRouteData().go(context),
|
||||
);
|
||||
context.read<HomeViewModel>().init();
|
||||
context.read<TabNavigationService>().onTabSelected(0);
|
||||
}
|
||||
},
|
||||
child: SvgPicture.asset(AssetsManager.logoSmall),
|
||||
@@ -63,7 +62,7 @@ class DesktopNavigationWidget extends StatelessWidget {
|
||||
context,
|
||||
() => const HomeRouteData().go(context),
|
||||
);
|
||||
context.read<HomeViewModel>().init();
|
||||
context.read<TabNavigationService>().onTabSelected(0);
|
||||
}
|
||||
},
|
||||
iconPath: AssetsManager.home,
|
||||
@@ -75,16 +74,11 @@ class DesktopNavigationWidget extends StatelessWidget {
|
||||
text: TendersStrings.tendersTitle,
|
||||
isActive: currentIndex == 1,
|
||||
onTap: () {
|
||||
// if (currentIndex == 1) {
|
||||
// return;
|
||||
// } else
|
||||
{
|
||||
Router.neglect(
|
||||
context,
|
||||
() => const TendersRouteData().go(context),
|
||||
);
|
||||
context.read<TendersViewModel>().init(context);
|
||||
}
|
||||
Router.neglect(
|
||||
context,
|
||||
() => const TendersRouteData().go(context),
|
||||
);
|
||||
context.read<TabNavigationService>().onTabSelected(1);
|
||||
},
|
||||
iconPath: AssetsManager.tenders,
|
||||
activeIconPath: AssetsManager.tendersActive,
|
||||
@@ -118,7 +112,7 @@ class DesktopNavigationWidget extends StatelessWidget {
|
||||
context,
|
||||
() => const NotificationRouteData().go(context),
|
||||
);
|
||||
context.read<NotificationViewModel>().init();
|
||||
context.read<TabNavigationService>().onTabSelected(3);
|
||||
}
|
||||
},
|
||||
iconPath: AssetsManager.notify,
|
||||
@@ -171,7 +165,8 @@ class DesktopNavigationWidget extends StatelessWidget {
|
||||
required String iconPath,
|
||||
required String activeIconPath,
|
||||
}) {
|
||||
final hasUnread = context.watch<HomeViewModel>().hasUnreadNotification;
|
||||
final hasUnread =
|
||||
context.watch<NotificationStateService>().hasUnreadNotification;
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
|
||||
Reference in New Issue
Block a user