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

Allow swipe on pages to navigate

parent 305bf0d4
No related branches found
No related tags found
1 merge request!24Resolve "Allow navigation with swipe"
Pipeline #4556 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.22 app.versionName=0.0.23
app.versionCode=22 app.versionCode=23
Allow swipe to navigate between pages.
Navigation entre pages par mouvement de "swipe".
...@@ -5,6 +5,9 @@ class BottomNavCubit extends HydratedCubit<int> { ...@@ -5,6 +5,9 @@ class BottomNavCubit extends HydratedCubit<int> {
void updateIndex(int index) => emit(index); void updateIndex(int index) => emit(index);
void movePrevious() => emit((state > 0) ? state - 1 : state);
void moveNext() => emit((state < 2) ? state + 1 : state);
void getHomePage() => emit(0); void getHomePage() => emit(0);
void getDiscoveriesPage() => emit(1); void getDiscoveriesPage() => emit(1);
void getStatisticsPage() => emit(2); void getStatisticsPage() => emit(2);
......
...@@ -27,6 +27,16 @@ class _SkeletonScreenState extends State<SkeletonScreen> { ...@@ -27,6 +27,16 @@ class _SkeletonScreenState extends State<SkeletonScreen> {
return BlocProvider<BottomNavCubit>( return BlocProvider<BottomNavCubit>(
create: (BuildContext context) => BottomNavCubit(), create: (BuildContext context) => BottomNavCubit(),
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( child: Scaffold(
appBar: StandardAppBar(notifyParent: refresh), appBar: StandardAppBar(notifyParent: refresh),
extendBodyBehindAppBar: false, extendBodyBehindAppBar: false,
...@@ -34,13 +44,17 @@ class _SkeletonScreenState extends State<SkeletonScreen> { ...@@ -34,13 +44,17 @@ class _SkeletonScreenState extends State<SkeletonScreen> {
builder: (BuildContext context, int state) { builder: (BuildContext context, int state) {
return AnimatedSwitcher( return AnimatedSwitcher(
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
child: pageNavigation.elementAt(state)); child: pageNavigation.elementAt(state),
);
}, },
), ),
bottomNavigationBar: const BottomNavBar(), bottomNavigationBar: const BottomNavBar(),
backgroundColor: Theme.of(context).colorScheme.background, backgroundColor: Theme.of(context).colorScheme.background,
), ),
); );
},
),
);
} }
refresh() { refresh() {
......
...@@ -21,7 +21,8 @@ class BottomNavBar extends StatelessWidget { ...@@ -21,7 +21,8 @@ class BottomNavBar extends StatelessWidget {
topRight: Radius.circular(16), topRight: Radius.circular(16),
), ),
), ),
child: BlocBuilder<BottomNavCubit, int>(builder: (BuildContext context, int state) { child: BlocBuilder<BottomNavCubit, int>(
builder: (BuildContext context, int state) {
return BottomNavigationBar( return BottomNavigationBar(
currentIndex: state, currentIndex: state,
onTap: (int index) => context.read<BottomNavCubit>().updateIndex(index), onTap: (int index) => context.read<BottomNavCubit>().updateIndex(index),
...@@ -45,7 +46,8 @@ class BottomNavBar extends StatelessWidget { ...@@ -45,7 +46,8 @@ class BottomNavBar extends StatelessWidget {
), ),
], ],
); );
}), },
),
); );
} }
} }
...@@ -3,7 +3,7 @@ description: Display scrobbles data and charts ...@@ -3,7 +3,7 @@ description: Display scrobbles data and charts
publish_to: 'none' publish_to: 'none'
version: 0.0.22+22 version: 0.0.23+23
environment: environment:
sdk: '^3.0.0' 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