Skip to content

Commit 0290b23

Browse files
authored
Merge pull request #189 from amoslai5128/master
Fixed a bug on auto scroll using raw pages when initial launch
2 parents 7a381f9 + 1f31aa4 commit 0290b23

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

lib/src/introduction_screen.dart

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ class IntroductionScreen extends StatefulWidget {
384384
'customProgress can only be used if isProgress = true',
385385
),
386386
assert(
387-
(infiniteAutoScroll && autoScrollDuration != null) ||
388-
!infiniteAutoScroll,
387+
(infiniteAutoScroll && autoScrollDuration != null) || !infiniteAutoScroll,
389388
'infiniteAutoScroll can only be true if autoScrollDuration != null',
390389
),
391390
super(key: key);
@@ -414,8 +413,7 @@ class IntroductionScreenState extends State<IntroductionScreen> {
414413
_autoScroll(widget.autoScrollDuration);
415414
if (widget.hideBottomOnKeyboard) {
416415
final keyboardVisibilityController = KeyboardVisibilityController();
417-
keyboardSubscription =
418-
keyboardVisibilityController.onChange.listen((bool visible) {
416+
keyboardSubscription = keyboardVisibilityController.onChange.listen((bool visible) {
419417
setState(() {
420418
_showBottom = !visible;
421419
});
@@ -439,9 +437,8 @@ class IntroductionScreenState extends State<IntroductionScreen> {
439437
Future<void> _autoScroll(int? _durationInt) async {
440438
if (_durationInt != null) {
441439
final Duration _autoscrollDuration = Duration(milliseconds: _durationInt);
442-
final _animationDuration =
443-
Duration(milliseconds: widget.animationDuration);
444-
final int pagesLenght = widget.pages!.length - 1;
440+
final _animationDuration = Duration(milliseconds: widget.animationDuration);
441+
final int pagesLength = getPagesLength() - 1;
445442
if (widget.infiniteAutoScroll) {
446443
while (true) {
447444
if (!mounted) {
@@ -450,11 +447,11 @@ class IntroductionScreenState extends State<IntroductionScreen> {
450447
await _movePage(
451448
_autoscrollDuration,
452449
_animationDuration,
453-
_currentPage < pagesLenght,
450+
_currentPage < pagesLength,
454451
);
455452
}
456453
} else {
457-
while (_currentPage < pagesLenght) {
454+
while (_currentPage < pagesLength) {
458455
if (!mounted) {
459456
break;
460457
}
@@ -468,8 +465,7 @@ class IntroductionScreenState extends State<IntroductionScreen> {
468465
}
469466
}
470467

471-
Future<void> _movePage(Duration autoscrollDuration,
472-
Duration animationDuration, bool forward) async {
468+
Future<void> _movePage(Duration autoscrollDuration, Duration animationDuration, bool forward) async {
473469
await Future.delayed(autoscrollDuration);
474470
if (!_isSkipPressed && !_isScrolling) {
475471
if (forward) {
@@ -487,11 +483,9 @@ class IntroductionScreenState extends State<IntroductionScreen> {
487483
}
488484
}
489485

490-
void next() =>
491-
{animateScroll(_currentPage + 1), FocusScope.of(context).unfocus()};
486+
void next() => {animateScroll(_currentPage + 1), FocusScope.of(context).unfocus()};
492487

493-
void previous() =>
494-
{animateScroll(_currentPage - 1), FocusScope.of(context).unfocus()};
488+
void previous() => {animateScroll(_currentPage - 1), FocusScope.of(context).unfocus()};
495489

496490
Future<void> _onSkip() async {
497491
if (widget.onSkip != null) {
@@ -550,8 +544,7 @@ class IntroductionScreenState extends State<IntroductionScreen> {
550544
child: widget.overrideSkip ??
551545
IntroButton(
552546
child: widget.skip!,
553-
style: widget.baseBtnStyle?.merge(widget.skipStyle) ??
554-
widget.skipStyle,
547+
style: widget.baseBtnStyle?.merge(widget.skipStyle) ?? widget.skipStyle,
555548
semanticLabel: widget.skipSemantic,
556549
onPressed: _onSkip,
557550
),
@@ -560,8 +553,7 @@ class IntroductionScreenState extends State<IntroductionScreen> {
560553
leftBtn = widget.overrideBack ??
561554
IntroButton(
562555
child: widget.back!,
563-
style: widget.baseBtnStyle?.merge(widget.backStyle) ??
564-
widget.backStyle,
556+
style: widget.baseBtnStyle?.merge(widget.backStyle) ?? widget.backStyle,
565557
semanticLabel: widget.backSemantic,
566558
onPressed: !_isScrolling ? previous : null,
567559
);
@@ -572,17 +564,15 @@ class IntroductionScreenState extends State<IntroductionScreen> {
572564
rightBtn = widget.overrideDone ??
573565
IntroButton(
574566
child: widget.done!,
575-
style: widget.baseBtnStyle?.merge(widget.doneStyle) ??
576-
widget.doneStyle,
567+
style: widget.baseBtnStyle?.merge(widget.doneStyle) ?? widget.doneStyle,
577568
semanticLabel: widget.doneSemantic,
578569
onPressed: !_isScrolling ? widget.onDone : null,
579570
);
580571
} else if (!isLastPage && widget.showNextButton) {
581572
rightBtn = widget.overrideNext ??
582573
IntroButton(
583574
child: widget.next!,
584-
style: widget.baseBtnStyle?.merge(widget.nextStyle) ??
585-
widget.nextStyle,
575+
style: widget.baseBtnStyle?.merge(widget.nextStyle) ?? widget.nextStyle,
586576
semanticLabel: widget.nextSemantic,
587577
onPressed: !_isScrolling ? next : null,
588578
);
@@ -620,9 +610,7 @@ class IntroductionScreenState extends State<IntroductionScreen> {
620610
?.mapIndexed(
621611
(index, page) => IntroPage(
622612
page: page,
623-
scrollController:
624-
(CustomList(widget.scrollControllers)
625-
?.elementAtOrNull(index)),
613+
scrollController: (CustomList(widget.scrollControllers)?.elementAtOrNull(index)),
626614
),
627615
)
628616
.toList() ??
@@ -661,18 +649,15 @@ class IntroductionScreenState extends State<IntroductionScreen> {
661649
child: widget.isProgress
662650
? widget.customProgress ??
663651
Semantics(
664-
label:
665-
"Page ${_currentPage.round() + 1} of ${getPagesLength()}",
652+
label: "Page ${_currentPage.round() + 1} of ${getPagesLength()}",
666653
excludeSemantics: true,
667654
child: DotsIndicator(
668655
reversed: widget.rtl,
669656
dotsCount: getPagesLength(),
670657
position: _currentPage,
671658
decorator: widget.dotsDecorator,
672-
onTap: widget.isProgressTap &&
673-
!widget.freeze
674-
? (pos) =>
675-
animateScroll(pos.toInt())
659+
onTap: widget.isProgressTap && !widget.freeze
660+
? (pos) => animateScroll(pos.toInt())
676661
: null,
677662
),
678663
)

0 commit comments

Comments
 (0)