Skip to content
Snippets Groups Projects
Commit 956d7e3a authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Allow swipe to navigate between pages

parent 5d677b31
No related branches found
No related tags found
1 merge request!36Resolve "Swipe to navigate"
Pipeline #4549 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=1.0.27
app.versionCode=28
app.versionName=1.0.28
app.versionCode=29
......@@ -5,6 +5,9 @@ class BottomNavCubit extends HydratedCubit<int> {
void updateIndex(int index) => emit(index);
void movePrevious() => emit((state > 0) ? state - 1 : state);
void moveNext() => emit((state < 3) ? state + 1 : state);
void getDemoPage() => emit(0);
void getGraphPage() => emit(1);
void getSettingsPage() => emit(2);
......
......@@ -33,18 +33,32 @@ class _SkeletonScreenState extends State<SkeletonScreen> {
create: (BuildContext context) => SettingsCubit(),
child: BlocProvider<BottomNavCubit>(
create: (BuildContext context) => BottomNavCubit(),
child: Scaffold(
extendBodyBehindAppBar: false,
appBar: StandardAppBar(),
body: BlocBuilder<BottomNavCubit, int>(
builder: (BuildContext context, int state) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: pageNavigation.elementAt(state));
},
),
bottomNavigationBar: const BottomNavBar(),
backgroundColor: Theme.of(context).colorScheme.background,
child: BlocBuilder<BottomNavCubit, int>(
builder: (BuildContext context, int state) {
return GestureDetector(
onHorizontalDragEnd: (dragDetail) {
if (dragDetail.velocity.pixelsPerSecond.dx < 1) {
context.read<BottomNavCubit>().moveNext();
} else {
context.read<BottomNavCubit>().movePrevious();
}
},
child: Scaffold(
extendBodyBehindAppBar: false,
appBar: StandardAppBar(),
body: BlocBuilder<BottomNavCubit, int>(
builder: (BuildContext context, int state) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: pageNavigation.elementAt(state),
);
},
),
bottomNavigationBar: const BottomNavBar(),
backgroundColor: Theme.of(context).colorScheme.background,
),
);
},
),
),
);
......
......@@ -21,35 +21,37 @@ class BottomNavBar extends StatelessWidget {
topRight: Radius.circular(16),
),
),
child: BlocBuilder<BottomNavCubit, int>(builder: (BuildContext context, int state) {
return BottomNavigationBar(
currentIndex: state,
onTap: (int index) => context.read<BottomNavCubit>().updateIndex(index),
type: BottomNavigationBarType.fixed,
elevation: 0,
backgroundColor: Colors.transparent,
selectedItemColor: Theme.of(context).colorScheme.primary,
unselectedItemColor: Theme.of(context).textTheme.bodySmall!.color,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: const Icon(Ionicons.image_outline),
label: tr('bottom_nav_sample'),
),
BottomNavigationBarItem(
icon: const Icon(Ionicons.pencil_outline),
label: tr('bottom_nav_chart'),
),
BottomNavigationBarItem(
icon: const Icon(Ionicons.settings_outline),
label: tr('bottom_nav_settings'),
),
BottomNavigationBarItem(
icon: const Icon(Ionicons.information_circle),
label: tr('bottom_nav_about'),
),
],
);
}),
child: BlocBuilder<BottomNavCubit, int>(
builder: (BuildContext context, int state) {
return BottomNavigationBar(
currentIndex: state,
onTap: (int index) => context.read<BottomNavCubit>().updateIndex(index),
type: BottomNavigationBarType.fixed,
elevation: 0,
backgroundColor: Colors.transparent,
selectedItemColor: Theme.of(context).colorScheme.primary,
unselectedItemColor: Theme.of(context).textTheme.bodySmall!.color,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: const Icon(Ionicons.image_outline),
label: tr('bottom_nav_sample'),
),
BottomNavigationBarItem(
icon: const Icon(Ionicons.pencil_outline),
label: tr('bottom_nav_chart'),
),
BottomNavigationBarItem(
icon: const Icon(Ionicons.settings_outline),
label: tr('bottom_nav_settings'),
),
BottomNavigationBarItem(
icon: const Icon(Ionicons.information_circle),
label: tr('bottom_nav_about'),
),
],
);
},
),
);
}
}
......@@ -3,7 +3,7 @@ description: A random application, for testing purpose only.
publish_to: 'none'
version: 1.0.27+28
version: 1.0.28+29
environment:
sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment