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,
|
||||
|
||||
@@ -3,16 +3,15 @@ import 'package:flutter_svg/svg.dart';
|
||||
import 'package:go_router/go_router.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 TabletNavigationWidget extends StatelessWidget {
|
||||
const TabletNavigationWidget({required this.currentIndex, super.key});
|
||||
@@ -41,7 +40,7 @@ class TabletNavigationWidget extends StatelessWidget {
|
||||
context,
|
||||
() => const HomeRouteData().go(context),
|
||||
);
|
||||
context.read<HomeViewModel>().init();
|
||||
context.read<TabNavigationService>().onTabSelected(0);
|
||||
}
|
||||
},
|
||||
iconPath: AssetsManager.home,
|
||||
@@ -60,7 +59,7 @@ class TabletNavigationWidget extends StatelessWidget {
|
||||
context,
|
||||
() => const TendersRouteData().go(context),
|
||||
);
|
||||
context.read<TendersViewModel>().init(context);
|
||||
context.read<TabNavigationService>().onTabSelected(1);
|
||||
}
|
||||
},
|
||||
iconPath: AssetsManager.tenders,
|
||||
@@ -94,7 +93,7 @@ class TabletNavigationWidget extends StatelessWidget {
|
||||
context,
|
||||
() => const NotificationRouteData().go(context),
|
||||
);
|
||||
context.read<NotificationViewModel>().init();
|
||||
context.read<TabNavigationService>().onTabSelected(3);
|
||||
}
|
||||
},
|
||||
iconPath: AssetsManager.notify,
|
||||
@@ -131,7 +130,8 @@ class TabletNavigationWidget extends StatelessWidget {
|
||||
required String iconPath,
|
||||
required String activeIconPath,
|
||||
}) {
|
||||
final hasUnread = context.watch<HomeViewModel>().hasUnreadNotification;
|
||||
final hasUnread =
|
||||
context.watch<NotificationStateService>().hasUnreadNotification;
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:tm_app/core/theme/colors.dart';
|
||||
import 'package:tm_app/core/utils/size_config.dart';
|
||||
|
||||
import '../../core/routes/app_routes.dart';
|
||||
import '../../view_models/home_view_model.dart';
|
||||
import '../../core/services/tab_navigation_service.dart';
|
||||
|
||||
PreferredSizeWidget tenderMobileAppBar({required String title}) {
|
||||
return PreferredSize(
|
||||
@@ -87,7 +87,7 @@ PreferredSizeWidget tabletAppBar({
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
onTap: () {
|
||||
Router.neglect(context, () => const HomeRouteData().go(context));
|
||||
context.read<HomeViewModel>().init();
|
||||
context.read<TabNavigationService>().onTabSelected(0);
|
||||
},
|
||||
child: SvgPicture.asset(AssetsManager.logoSmall),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user