123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import 'package:cs_resources/theme/app_colors_theme.dart';
- import 'package:flutter/src/widgets/framework.dart';
- import 'package:flutter_hooks/flutter_hooks.dart';
- import 'package:hooks_riverpod/hooks_riverpod.dart';
- import 'package:auto_route/auto_route.dart';
- import 'package:flutter/material.dart';
- import 'package:plugin_basic/constants/app_constant.dart';
- import 'package:shared/utils/device_utils.dart';
- import 'package:shared/utils/event_bus.dart';
- import 'package:shared/utils/log_utils.dart';
- import '../../router/page/main_page_router.dart';
- import 'package:router/ext/auto_router_extensions.dart';
- import 'main_view_model.dart';
- @RoutePage()
- class MainPage extends HookConsumerWidget {
- const MainPage({super.key});
- //启动当前页面
- static void startInstance({BuildContext? context}) {
- if (context != null) {
- context.router.popUntilRoot();
- context.router.replace(const MainPageRoute());
- } else {
- appRouter.popUntilRoot();
- appRouter.replace(const MainPageRoute());
- }
- }
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final viewModel = ref.watch(mainViewModelProvider.notifier);
- final state = ref.watch(mainViewModelProvider);
- useEffect(() {
- Future.microtask(() => viewModel.fetchUserInfo());
- return () {
- };
- }, []);
- return AutoTabsScaffold(
- routes: const [
- HomePageRoute(),
- VisitorPageRoute(),
- FeedbackPageRoute(),
- MePageRoute(),
- ],
- transitionBuilder: (context, child, animation) => FadeTransition(
- opacity: animation,
- child: child,
- ),
- bottomNavigationBuilder: (context, tabsRouter) {
- return BottomNavigationBar(
- elevation: 10,
- backgroundColor: context.appColors.backgroundWhite,
- type: BottomNavigationBarType.fixed,
- currentIndex: tabsRouter.activeIndex,
- onTap: tabsRouter.setActiveIndex,
- unselectedLabelStyle: const TextStyle(color: AppColorsTheme.color666666, fontWeight: FontWeight.w400),
- selectedLabelStyle: TextStyle(color: context.appColors.textPrimary, fontWeight: FontWeight.w400),
- unselectedFontSize: 12,
- selectedFontSize: 12,
- items: () {
- var items = <BottomNavigationBarItem>[];
- state.bottomMap.forEach((k, v) {
- items.add(BottomNavigationBarItem(
- label: k,
- icon: v[0],
- activeIcon: DeviceUtils.isDarkMode(context) ? v[2] : v[1],
- ));
- });
- return items;
- }(),
- );
- },
- );
- }
- }
|