mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
Added page swipe for navigation
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -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[
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user