update(MainScreen): Fix Timer cannot cancel when switching tabs
This commit is contained in:
@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:badges/badges.dart' as badges;
|
||||
import 'package:persistent_bottom_nav_bar/persistent_bottom_nav_bar.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||
|
||||
import '../../product/utils/permission_handler.dart';
|
||||
import '../../product/permission/notification_permission.dart';
|
||||
@@ -147,79 +147,75 @@ class _MainScreenState extends State<MainScreen> with WidgetsBindingObserver {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
}
|
||||
|
||||
List<PersistentBottomNavBarItem> _navBarsItems() {
|
||||
return [
|
||||
PersistentBottomNavBarItem(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.home),
|
||||
title: appLocalization(context).home_page_destination,
|
||||
activeColorPrimary: Colors.blue,
|
||||
inactiveColorPrimary: Colors.grey,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.home_outlined),
|
||||
),
|
||||
PersistentBottomNavBarItem(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.settings),
|
||||
title: appLocalization(context).manager_page_destination,
|
||||
activeColorPrimary: Colors.blue,
|
||||
inactiveColorPrimary: Colors.grey,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.settings_outlined),
|
||||
),
|
||||
PersistentBottomNavBarItem(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.location_on),
|
||||
title: appLocalization(context).map_page_destination,
|
||||
activeColorPrimary: Colors.blue,
|
||||
inactiveColorPrimary: Colors.grey,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.location_on_outlined),
|
||||
),
|
||||
PersistentBottomNavBarItem(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.history),
|
||||
title: appLocalization(context).history_page_destination,
|
||||
activeColorPrimary: Colors.blue,
|
||||
inactiveColorPrimary: Colors.grey,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.history_outlined),
|
||||
),
|
||||
PersistentBottomNavBarItem(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.group),
|
||||
title: appLocalization(context).group_page_destination,
|
||||
activeColorPrimary: Colors.blue,
|
||||
inactiveColorPrimary: Colors.grey,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.group_outlined),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
List<Widget> _buildScreens() {
|
||||
return [
|
||||
BlocProvider(
|
||||
child: HomeScreen(
|
||||
persistentTabController: controller,
|
||||
),
|
||||
blocBuilder: () => HomeBloc(),
|
||||
),
|
||||
BlocProvider(
|
||||
child: const DevicesManagerScreen(),
|
||||
blocBuilder: () => DevicesManagerBloc()),
|
||||
BlocProvider(
|
||||
child: const MapScreen(),
|
||||
blocBuilder: () => MapBloc(),
|
||||
),
|
||||
BlocProvider(
|
||||
child: const DeviceLogsScreen(),
|
||||
blocBuilder: () => DeviceLogsBloc(),
|
||||
),
|
||||
BlocProvider(
|
||||
child: const InterFamilyScreen(),
|
||||
blocBuilder: () => InterFamilyBloc(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<PersistentTabConfig> tabs = [
|
||||
PersistentTabConfig(
|
||||
screen: BlocProvider(
|
||||
child: const HomeScreen(),
|
||||
blocBuilder: () => HomeBloc(),
|
||||
),
|
||||
item: ItemConfig(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.home),
|
||||
title: appLocalization(context).home_page_destination,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.home_outlined),
|
||||
iconSize: 30,
|
||||
),
|
||||
),
|
||||
PersistentTabConfig(
|
||||
screen: BlocProvider(
|
||||
child: const DevicesManagerScreen(),
|
||||
blocBuilder: () => DevicesManagerBloc(),
|
||||
),
|
||||
item: ItemConfig(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.settings),
|
||||
title: appLocalization(context).manager_page_destination,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.settings_outlined),
|
||||
iconSize: 30,
|
||||
),
|
||||
),
|
||||
PersistentTabConfig(
|
||||
screen: BlocProvider(
|
||||
child: const MapScreen(),
|
||||
blocBuilder: () => MapBloc(),
|
||||
),
|
||||
item: ItemConfig(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.location_on),
|
||||
title: appLocalization(context).map_page_destination,
|
||||
inactiveIcon: IconConstants.instance
|
||||
.getMaterialIcon(Icons.location_on_outlined),
|
||||
iconSize: 30,
|
||||
),
|
||||
),
|
||||
PersistentTabConfig(
|
||||
screen: BlocProvider(
|
||||
child: const DeviceLogsScreen(),
|
||||
blocBuilder: () => DeviceLogsBloc(),
|
||||
),
|
||||
item: ItemConfig(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.history),
|
||||
title: appLocalization(context).history_page_destination,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.history_outlined),
|
||||
iconSize: 30,
|
||||
),
|
||||
),
|
||||
PersistentTabConfig(
|
||||
screen: BlocProvider(
|
||||
child: const InterFamilyScreen(),
|
||||
blocBuilder: () => InterFamilyBloc(),
|
||||
),
|
||||
item: ItemConfig(
|
||||
icon: IconConstants.instance.getMaterialIcon(Icons.group),
|
||||
title: appLocalization(context).group_page_destination,
|
||||
inactiveIcon:
|
||||
IconConstants.instance.getMaterialIcon(Icons.group_outlined),
|
||||
iconSize: 30,
|
||||
),
|
||||
),
|
||||
];
|
||||
return StreamBuilder<bool>(
|
||||
stream: mainBloc.streamThemeMode,
|
||||
initialData: isLight,
|
||||
@@ -368,32 +364,27 @@ class _MainScreenState extends State<MainScreen> with WidgetsBindingObserver {
|
||||
],
|
||||
),
|
||||
body: PersistentTabView(
|
||||
context,
|
||||
controller: controller,
|
||||
screens: _buildScreens(),
|
||||
items: _navBarsItems(),
|
||||
handleAndroidBackButtonPress: true,
|
||||
resizeToAvoidBottomInset: true,
|
||||
stateManagement: false,
|
||||
controller: controller,
|
||||
tabs: tabs,
|
||||
navBarBuilder: (navBarConfig) => Style6BottomNavBar(
|
||||
navBarConfig: navBarConfig,
|
||||
navBarDecoration: NavBarDecoration(
|
||||
color: themeModeSnapshot.data! ? Colors.white : Colors.black,
|
||||
borderRadius: BorderRadius.circular(context.mediumValue),
|
||||
padding: const EdgeInsets.all(10)),
|
||||
),
|
||||
backgroundColor:
|
||||
themeModeSnapshot.data! ? Colors.white : Colors.black,
|
||||
decoration: NavBarDecoration(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
colorBehindNavBar:
|
||||
themeModeSnapshot.data! ? Colors.white : Colors.black,
|
||||
navBarOverlap: const NavBarOverlap.none(),
|
||||
// margin: EdgeInsets.only(
|
||||
// left: context.lowValue,
|
||||
// bottom: context.dynamicHeight(0.02),
|
||||
// right: context.lowValue),
|
||||
screenTransitionAnimation: const ScreenTransitionAnimation(
|
||||
curve: Curves.bounceInOut,
|
||||
duration: Duration(milliseconds: 200),
|
||||
),
|
||||
animationSettings: const NavBarAnimationSettings(
|
||||
navBarItemAnimation: ItemAnimationSettings(
|
||||
duration: Duration(milliseconds: 200),
|
||||
curve: Curves.bounceInOut,
|
||||
),
|
||||
screenTransitionAnimation: ScreenTransitionAnimationSettings(
|
||||
animateTabTransition: true,
|
||||
curve: Curves.bounceInOut,
|
||||
duration: Duration(milliseconds: 200),
|
||||
),
|
||||
),
|
||||
navBarStyle: NavBarStyle.style13,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user