Update Bottom Navigator in MainScreen
This commit is contained in:
@@ -5,6 +5,7 @@ import 'dart:developer';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent-tab-view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:badges/badges.dart' as badges;
|
||||
import 'package:sfm_app/feature/home/home_bloc.dart';
|
||||
@@ -17,8 +18,8 @@ import '../devices/devices_manager_screen.dart';
|
||||
import '../home/home_screen.dart';
|
||||
import '../inter_family/inter_family_bloc.dart';
|
||||
import '../inter_family/inter_family_screen.dart';
|
||||
import '../log/device_logs_bloc.dart';
|
||||
import '../log/device_logs_screen.dart';
|
||||
import '../device_log/device_logs_bloc.dart';
|
||||
import '../device_log/device_logs_screen.dart';
|
||||
import 'main_bloc.dart';
|
||||
import '../map/map_bloc.dart';
|
||||
import '../map/map_screen.dart';
|
||||
@@ -102,6 +103,76 @@ class _MainScreenState extends State<MainScreen> with WidgetsBindingObserver {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
}
|
||||
|
||||
PersistentTabController controller = PersistentTabController(initialIndex: 0);
|
||||
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: const HomeScreen(),
|
||||
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) {
|
||||
ThemeNotifier themeNotifier = context.watch<ThemeNotifier>();
|
||||
@@ -204,16 +275,16 @@ class _MainScreenState extends State<MainScreen> with WidgetsBindingObserver {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: StreamBuilder<String>(
|
||||
stream: mainBloc.streamTitle,
|
||||
initialData: titlePage,
|
||||
builder: (context, titleSnapshot) {
|
||||
return Text(
|
||||
titleSnapshot.data ?? ApplicationConstants.APP_NAME,
|
||||
);
|
||||
},
|
||||
),
|
||||
// centerTitle: true,
|
||||
// title: StreamBuilder<String>(
|
||||
// stream: mainBloc.streamTitle,
|
||||
// initialData: titlePage,
|
||||
// builder: (context, titleSnapshot) {
|
||||
// return Text(
|
||||
// titleSnapshot.data ?? ApplicationConstants.APP_NAME,
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
actions: [
|
||||
StreamBuilder<bool>(
|
||||
stream: mainBloc.streamThemeMode,
|
||||
@@ -306,13 +377,8 @@ class _MainScreenState extends State<MainScreen> with WidgetsBindingObserver {
|
||||
},
|
||||
),
|
||||
PopupMenuButton(
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(8.0),
|
||||
bottomRight: Radius.circular(8.0),
|
||||
topLeft: Radius.circular(8.0),
|
||||
topRight: Radius.circular(8.0),
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
icon: const Icon(Icons.more_vert),
|
||||
itemBuilder: (context) {
|
||||
@@ -355,27 +421,53 @@ class _MainScreenState extends State<MainScreen> with WidgetsBindingObserver {
|
||||
)
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: Container(
|
||||
decoration:
|
||||
BoxDecoration(borderRadius: BorderRadius.circular(50)),
|
||||
padding: context.paddingLow,
|
||||
child: NavigationBar(
|
||||
onDestinationSelected: (index) {
|
||||
currentPageIndex = index;
|
||||
mainBloc.sinkCurrentPageIndex.add(currentPageIndex);
|
||||
checkSelectedIndex(currentPageIndex);
|
||||
},
|
||||
selectedIndex: indexSnapshot.data ?? currentPageIndex,
|
||||
destinations: roleSnapshot.data == RoleEnums.USER.name
|
||||
? userDestinations
|
||||
: modDestinations,
|
||||
// bottomNavigationBar: Container(
|
||||
// decoration:
|
||||
// BoxDecoration(borderRadius: BorderRadius.circular(50)),
|
||||
// padding: context.paddingLow,
|
||||
// child: NavigationBar(
|
||||
// onDestinationSelected: (index) {
|
||||
// currentPageIndex = index;
|
||||
// mainBloc.sinkCurrentPageIndex.add(currentPageIndex);
|
||||
// checkSelectedIndex(currentPageIndex);
|
||||
// },
|
||||
// selectedIndex: indexSnapshot.data ?? currentPageIndex,
|
||||
// destinations: roleSnapshot.data == RoleEnums.USER.name
|
||||
// ? userDestinations
|
||||
// : modDestinations,
|
||||
// ),
|
||||
// ),
|
||||
// body: IndexedStack(
|
||||
// index: indexSnapshot.data ?? currentPageIndex,
|
||||
// children: roleSnapshot.data == RoleEnums.USER.name
|
||||
// ? userBody
|
||||
// : modBody,
|
||||
// ),
|
||||
body: PersistentTabView(
|
||||
context,
|
||||
controller: controller,
|
||||
screens: _buildScreens(),
|
||||
items: _navBarsItems(),
|
||||
confineInSafeArea: true,
|
||||
handleAndroidBackButtonPress: true,
|
||||
resizeToAvoidBottomInset: true,
|
||||
stateManagement: true,
|
||||
hideNavigationBarWhenKeyboardShows: true,
|
||||
// backgroundColor: Colors.transparent,
|
||||
decoration: NavBarDecoration(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
),
|
||||
),
|
||||
body: IndexedStack(
|
||||
index: indexSnapshot.data ?? currentPageIndex,
|
||||
children: roleSnapshot.data == RoleEnums.USER.name
|
||||
? userBody
|
||||
: modBody,
|
||||
popAllScreensOnTapOfSelectedTab: true,
|
||||
itemAnimationProperties: const ItemAnimationProperties(
|
||||
duration: Duration(milliseconds: 200),
|
||||
curve: Curves.bounceInOut,
|
||||
),
|
||||
screenTransitionAnimation: const ScreenTransitionAnimation(
|
||||
animateTabTransition: true,
|
||||
curve: Curves.linear,
|
||||
duration: Duration(milliseconds: 200),
|
||||
),
|
||||
navBarStyle: NavBarStyle.style4,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user