Add scroll wheel support for intro screen
This commit is contained in:
parent
7318ce7d9a
commit
b6e35f6f92
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:wonders/common_libs.dart';
|
||||
import 'package:wonders/ui/common/app_icons.dart';
|
||||
import 'package:wonders/ui/common/app_icons.dart';
|
||||
import 'package:wonders/ui/common/controls/app_page_indicator.dart';
|
||||
import 'package:wonders/ui/common/gradient_container.dart';
|
||||
import 'package:wonders/ui/common/static_text_scale.dart';
|
||||
@ -25,6 +26,8 @@ class _IntroScreenState extends State<IntroScreen> {
|
||||
late final PageController _pageController = PageController()..addListener(_handlePageChanged);
|
||||
final ValueNotifier<int> _currentPage = ValueNotifier(0);
|
||||
bool get _isOnLastPage => _currentPage.value.round() == pageData.length - 1;
|
||||
bool get _isOnFirstPage => _currentPage.value.round() == 0;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
@ -48,12 +51,17 @@ class _IntroScreenState extends State<IntroScreen> {
|
||||
duration: $styles.times.fast, curve: Curves.easeOut);
|
||||
}
|
||||
|
||||
void _handleNavTextDoubleTapped() {
|
||||
void _handleNavTextSemanticTap() => _incrementPage(1);
|
||||
|
||||
void _incrementPage(int dir){
|
||||
final int current = _pageController.page!.round();
|
||||
if (_isOnLastPage) return;
|
||||
_pageController.animateToPage(current + 1, duration: 250.ms, curve: Curves.easeIn);
|
||||
if (_isOnLastPage && dir > 0) return;
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
// 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();
|
||||
|
||||
/// Return resulting widget tree
|
||||
return DefaultTextColor(
|
||||
return Listener(
|
||||
onPointerSignal: (signal){
|
||||
if(signal is PointerScrollEvent){
|
||||
_handleScrollWheel(signal.scrollDelta.dy);
|
||||
}
|
||||
},
|
||||
child: DefaultTextColor(
|
||||
color: $styles.colors.offWhite,
|
||||
child: Container(
|
||||
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,
|
||||
child: Semantics(
|
||||
onTapHint: $strings.introSemanticNavigate,
|
||||
onTap: _isOnLastPage ? null : _handleNavTextDoubleTapped,
|
||||
onTap: _isOnLastPage ? null : _handleNavTextSemanticTap,
|
||||
child: Text($strings.introSemanticSwipeLeft, style: $styles.text.bodySmall),
|
||||
),
|
||||
);
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: wonders
|
||||
description: Explore the famous wonders of the world.
|
||||
publish_to: "none"
|
||||
version: 2.0.16+5
|
||||
version: 2.0.17+6
|
||||
|
||||
environment:
|
||||
sdk: ">=2.17.0 <3.0.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user