Added page swipe for navigation

This commit is contained in:
Mohammad Salameh
2024-03-10 16:57:12 +03:00
parent c03b2b248d
commit f11b6d8d32
10 changed files with 84 additions and 22 deletions

View File

@ -147,11 +147,13 @@ class NavCubit extends Cubit<NavState> {
const MenuView(),
];
Widget get currentPage => NavCubit().pages[pageIndex];
final PageController pageController = PageController();
void updatePageIndex(int index, BuildContext context) {
emit(NavChangePage());
void updatePageIndex(int index) {
pageIndex = index;
pageController.animateToPage(index,
duration: const Duration(milliseconds: 150), curve: Curves.easeIn);
emit(NavChangePage());
}
}

View File

@ -14,19 +14,26 @@ class AppBody extends StatelessWidget {
return BlocBuilder<NavCubit, NavState>(
builder: (context, state) {
return Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
Assets.imagesBackground,
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
Assets.imagesBackground,
),
fit: BoxFit.cover,
opacity: 0.4,
),
fit: BoxFit.cover,
opacity: 0.4,
),
),
child: NavCubit.of(context).currentPage,
);
child: PageView(
onPageChanged: (int index) {
NavCubit.of(context).updatePageIndex(index);
},
controller: NavCubit.of(context).pageController,
children: NavCubit.of(context).pages,
)
// NavCubit.of(context).currentPage,
);
},
);
}

View File

@ -19,6 +19,7 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
child: AppBar(
backgroundColor: Colors.transparent,
leadingWidth: 150,
toolbarHeight: Constants.appBarHeight,
leading: NavCubit.appBarLeading[
NavCubit().bottomNavItems[NavCubit.pageIndex].label],
actions: NavCubit.appBarActions[

View File

@ -20,7 +20,7 @@ class DefaultNavBar extends StatelessWidget {
child: BottomNavigationBar(
backgroundColor: Colors.transparent,
onTap: (int index) {
cubit.updatePageIndex(index, context);
cubit.updatePageIndex(index);
if (DevicesCubit.get(context).chosenCategoryView != null) {
DevicesCubit().clearCategoriesSelection(context);
}