Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking -> turn _currentpage into an int instead of double #180

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_keyboard_visibility","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility-5.4.0\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_keyboard_visibility","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility-5.4.0\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_keyboard_visibility_macos","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_macos-1.0.0\\\\","native_build":false,"dependencies":[]}],"linux":[{"name":"flutter_keyboard_visibility_linux","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_linux-1.0.0\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"flutter_keyboard_visibility_windows","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_windows-1.0.0\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"flutter_keyboard_visibility_web","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_web-2.0.0\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_keyboard_visibility","dependencies":["flutter_keyboard_visibility_linux","flutter_keyboard_visibility_macos","flutter_keyboard_visibility_web","flutter_keyboard_visibility_windows"]},{"name":"flutter_keyboard_visibility_linux","dependencies":[]},{"name":"flutter_keyboard_visibility_macos","dependencies":[]},{"name":"flutter_keyboard_visibility_web","dependencies":[]},{"name":"flutter_keyboard_visibility_windows","dependencies":[]}],"date_created":"2023-04-19 21:51:08.892689","version":"3.7.11"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_keyboard_visibility","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility-5.4.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_keyboard_visibility","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility-5.4.1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_keyboard_visibility_macos","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_macos-1.0.0\\\\","native_build":false,"dependencies":[]}],"linux":[{"name":"flutter_keyboard_visibility_linux","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_linux-1.0.0\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"flutter_keyboard_visibility_windows","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_windows-1.0.0\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"flutter_keyboard_visibility_web","path":"C:\\\\Users\\\\gian_\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_keyboard_visibility_web-2.0.0\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_keyboard_visibility","dependencies":["flutter_keyboard_visibility_linux","flutter_keyboard_visibility_macos","flutter_keyboard_visibility_web","flutter_keyboard_visibility_windows"]},{"name":"flutter_keyboard_visibility_linux","dependencies":[]},{"name":"flutter_keyboard_visibility_macos","dependencies":[]},{"name":"flutter_keyboard_visibility_web","dependencies":[]},{"name":"flutter_keyboard_visibility_windows","dependencies":[]}],"date_created":"2023-05-05 23:41:59.624530","version":"3.7.12"}
33 changes: 12 additions & 21 deletions lib/src/introduction_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import '/src/model/position.dart';
import '/src/ui/intro_button.dart';
import '/src/ui/intro_page.dart';

bool defaultCanProgressFunction(double page) {
bool defaultCanProgressFunction(int page) {
return true;
}

Expand Down Expand Up @@ -396,7 +396,7 @@ class IntroductionScreen extends StatefulWidget {

class IntroductionScreenState extends State<IntroductionScreen> {
late PageController _pageController;
double _currentPage = 0.0;
int _currentPage = 0;
bool _isSkipPressed = false;
bool _isScrolling = false;
late bool _showBottom;
Expand All @@ -410,7 +410,7 @@ class IntroductionScreenState extends State<IntroductionScreen> {
super.initState();
_showBottom = widget.showBottomPart;
final int initialPage = min(widget.initialPage, getPagesLength() - 1);
_currentPage = initialPage.toDouble();
_currentPage = initialPage;
_pageController = PageController(initialPage: initialPage);
_autoScrollOperation =
CancelableOperation.fromFuture(_autoScroll(widget.autoScrollDuration));
Expand Down Expand Up @@ -439,16 +439,11 @@ class IntroductionScreenState extends State<IntroductionScreen> {
return (widget.pages ?? widget.rawPages!).length;
}

int getCurrentPageNumber() => _currentPage.round();
Pyozer marked this conversation as resolved.
Show resolved Hide resolved

Future<void> _autoScroll(int? _durationInt) async {
if (_durationInt != null) {
final Duration _duration = Duration(milliseconds: _durationInt);
final int pagesLenght = widget.pages!.length - 1;
for (int i = 0; i < pagesLenght; i++) {
if (getCurrentPageNumber() == pagesLenght) {
break;
}
while (_currentPage < pagesLenght) {
await Future.delayed(_duration);
if (!_isSkipPressed && !_isScrolling) {
_pageController.nextPage(
Expand All @@ -460,15 +455,11 @@ class IntroductionScreenState extends State<IntroductionScreen> {
}
}

void next() => {
animateScroll(getCurrentPageNumber() + 1),
FocusScope.of(context).unfocus()
};
void next() =>
{animateScroll(_currentPage + 1), FocusScope.of(context).unfocus()};

void previous() => {
animateScroll(getCurrentPageNumber() - 1),
FocusScope.of(context).unfocus()
};
void previous() =>
{animateScroll(_currentPage - 1), FocusScope.of(context).unfocus()};

Future<void> _onSkip() async {
if (widget.onSkip != null) {
Expand All @@ -489,14 +480,14 @@ class IntroductionScreenState extends State<IntroductionScreen> {
Future<void> animateScroll(int page) async {
bool isValidToProgress = widget.canProgress(_currentPage);
if (isValidToProgress) {
setState(() => _isScrolling = true);
_isScrolling = true;
await _pageController.animateToPage(
max(min(page, getPagesLength() - 1), 0),
duration: Duration(milliseconds: widget.animationDuration),
curve: widget.curve,
);
if (mounted) {
setState(() => _isScrolling = false);
_isScrolling = false;
}
}
}
Expand All @@ -505,15 +496,15 @@ class IntroductionScreenState extends State<IntroductionScreen> {
final metrics = notification.metrics;
if (metrics is PageMetrics && metrics.page != null) {
if (mounted) {
setState(() => _currentPage = metrics.page!);
setState(() => _currentPage = metrics.page!.round());
}
}
return false;
}

@override
Widget build(BuildContext context) {
final isLastPage = (getCurrentPageNumber() == getPagesLength() - 1);
final isLastPage = (_currentPage == getPagesLength() - 1);

Widget? leftBtn;
if (widget.showSkipButton) {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ dependencies:
flutter:
sdk: flutter

dots_indicator: ^2.1.0
dots_indicator: ^3.0.0
collection: ^1.17.0
flutter_keyboard_visibility: ^5.4.0
flutter_keyboard_visibility: ^5.4.1

dev_dependencies:
flutter_test:
Expand Down