Add scroll wheel support for intro screen

This commit is contained in:
Shawn 2023-07-31 10:14:04 -06:00
parent 7318ce7d9a
commit b6e35f6f92
2 changed files with 108 additions and 93 deletions

View File

@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:wonders/common_libs.dart'; import 'package:wonders/common_libs.dart';
import 'package:wonders/ui/common/app_icons.dart'; import 'package:wonders/ui/common/app_icons.dart';
@ -25,6 +26,8 @@ class _IntroScreenState extends State<IntroScreen> {
late final PageController _pageController = PageController()..addListener(_handlePageChanged); late final PageController _pageController = PageController()..addListener(_handlePageChanged);
final ValueNotifier<int> _currentPage = ValueNotifier(0); final ValueNotifier<int> _currentPage = ValueNotifier(0);
bool get _isOnLastPage => _currentPage.value.round() == pageData.length - 1; bool get _isOnLastPage => _currentPage.value.round() == pageData.length - 1;
bool get _isOnFirstPage => _currentPage.value.round() == 0;
@override @override
void dispose() { void dispose() {
_pageController.dispose(); _pageController.dispose();
@ -48,12 +51,17 @@ class _IntroScreenState extends State<IntroScreen> {
duration: $styles.times.fast, curve: Curves.easeOut); duration: $styles.times.fast, curve: Curves.easeOut);
} }
void _handleNavTextDoubleTapped() { void _handleNavTextSemanticTap() => _incrementPage(1);
void _incrementPage(int dir){
final int current = _pageController.page!.round(); final int current = _pageController.page!.round();
if (_isOnLastPage) return; if (_isOnLastPage && dir > 0) return;
_pageController.animateToPage(current + 1, duration: 250.ms, curve: Curves.easeIn); if (_isOnFirstPage && dir < 0) return;
_pageController.animateToPage(current + dir, duration: 250.ms, curve: Curves.easeIn);
} }
void _handleScrollWheel(double delta) => _incrementPage(delta >0? 1 : -1);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Set the page data, as strings may have changed based on locale // Set the page data, as strings may have changed based on locale
@ -70,7 +78,13 @@ class _IntroScreenState extends State<IntroScreen> {
final List<Widget> pages = pageData.map((e) => _Page(data: e)).toList(); final List<Widget> pages = pageData.map((e) => _Page(data: e)).toList();
/// Return resulting widget tree /// Return resulting widget tree
return DefaultTextColor( return Listener(
onPointerSignal: (signal){
if(signal is PointerScrollEvent){
_handleScrollWheel(signal.scrollDelta.dy);
}
},
child: DefaultTextColor(
color: $styles.colors.offWhite, color: $styles.colors.offWhite,
child: Container( child: Container(
color: $styles.colors.black, color: $styles.colors.black,
@ -164,6 +178,7 @@ class _IntroScreenState extends State<IntroScreen> {
), ),
), ),
), ),
),
); );
} }
@ -215,7 +230,7 @@ class _IntroScreenState extends State<IntroScreen> {
duration: $styles.times.fast, duration: $styles.times.fast,
child: Semantics( child: Semantics(
onTapHint: $strings.introSemanticNavigate, onTapHint: $strings.introSemanticNavigate,
onTap: _isOnLastPage ? null : _handleNavTextDoubleTapped, onTap: _isOnLastPage ? null : _handleNavTextSemanticTap,
child: Text($strings.introSemanticSwipeLeft, style: $styles.text.bodySmall), child: Text($strings.introSemanticSwipeLeft, style: $styles.text.bodySmall),
), ),
); );

View File

@ -1,7 +1,7 @@
name: wonders name: wonders
description: Explore the famous wonders of the world. description: Explore the famous wonders of the world.
publish_to: "none" publish_to: "none"
version: 2.0.16+5 version: 2.0.17+6
environment: environment:
sdk: ">=2.17.0 <3.0.0" sdk: ">=2.17.0 <3.0.0"