Skip to content

Commit 49aaad2

Browse files
authored
Merge pull request #234 from flowhorn/master
feat(introduction_screen): Enable override* buttons to receive onPressed callback
2 parents 624e5df + 3a7e769 commit 49aaad2

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

lib/src/introduction_screen.dart

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,32 @@ class IntroductionScreen extends StatefulWidget {
4141

4242
/// Override pre-made done button.
4343
/// You can what you want (button, text, image, ...)
44-
final Widget? overrideDone;
44+
final Widget Function(BuildContext context, Function()? onPressed)?
45+
overrideDone;
4546

4647
/// Skip button child for the pre-made TextButton
4748
final Widget? skip;
4849

4950
/// Override pre-made skip button.
5051
/// You can what you want (button, text, image, ...)
51-
final Widget? overrideSkip;
52+
final Widget Function(BuildContext context, Function() onPressed)?
53+
overrideSkip;
5254

5355
/// Next button child for the pre-made TextButton
5456
final Widget? next;
5557

5658
/// Override pre-made next button.
5759
/// You can what you want (button, text, image, ...)
58-
final Widget? overrideNext;
60+
final Widget Function(BuildContext context, Function()? onPressed)?
61+
overrideNext;
5962

6063
/// Back button child for the pre-made TextButton
6164
final Widget? back;
6265

6366
/// Override pre-made back button.
6467
/// You can what you want (button, text, image, ...)
65-
final Widget? overrideBack;
68+
final Widget Function(BuildContext context, Function()? onPressed)?
69+
overrideBack;
6670

6771
/// Is the Skip button should be display
6872
///
@@ -561,49 +565,53 @@ class IntroductionScreenState extends State<IntroductionScreen> {
561565
maintainAnimation: true,
562566
// Needs to be true to maintain size
563567
maintainSize: true,
564-
child: widget.overrideSkip ??
565-
IntroButton(
566-
child: widget.skip!,
567-
style: widget.baseBtnStyle?.merge(widget.skipStyle) ??
568-
widget.skipStyle,
569-
semanticLabel: widget.skipSemantic,
570-
onPressed: _onSkip,
571-
),
568+
child: widget.overrideSkip != null
569+
? widget.overrideSkip!(context, _onSkip)
570+
: IntroButton(
571+
child: widget.skip!,
572+
style: widget.baseBtnStyle?.merge(widget.skipStyle) ??
573+
widget.skipStyle,
574+
semanticLabel: widget.skipSemantic,
575+
onPressed: _onSkip,
576+
),
572577
);
573578
} else if (widget.showBackButton &&
574579
getCurrentPage() > 0 &&
575580
widget.canProgress(getCurrentPage())) {
576-
leftBtn = widget.overrideBack ??
577-
IntroButton(
578-
child: widget.back!,
579-
style: widget.baseBtnStyle?.merge(widget.backStyle) ??
580-
widget.backStyle,
581-
semanticLabel: widget.backSemantic,
582-
onPressed: !_isScrolling ? previous : null,
583-
);
581+
leftBtn = widget.overrideBack != null
582+
? widget.overrideBack!(context, !_isScrolling ? previous : null)
583+
: IntroButton(
584+
child: widget.back!,
585+
style: widget.baseBtnStyle?.merge(widget.backStyle) ??
586+
widget.backStyle,
587+
semanticLabel: widget.backSemantic,
588+
onPressed: !_isScrolling ? previous : null,
589+
);
584590
}
585591

586592
Widget? rightBtn;
587593
if (isLastPage && widget.showDoneButton) {
588-
rightBtn = widget.overrideDone ??
589-
IntroButton(
590-
child: widget.done!,
591-
style: widget.baseBtnStyle?.merge(widget.doneStyle) ??
592-
widget.doneStyle,
593-
semanticLabel: widget.doneSemantic,
594-
onPressed: !_isScrolling ? widget.onDone : null,
595-
);
594+
rightBtn = widget.overrideDone != null
595+
? widget.overrideDone!(context, !_isScrolling ? widget.onDone : null)
596+
: IntroButton(
597+
child: widget.done!,
598+
style: widget.baseBtnStyle?.merge(widget.doneStyle) ??
599+
widget.doneStyle,
600+
semanticLabel: widget.doneSemantic,
601+
onPressed: !_isScrolling ? widget.onDone : null,
602+
);
596603
} else if (!isLastPage &&
597604
widget.showNextButton &&
598605
widget.canProgress(getCurrentPage())) {
599-
rightBtn = widget.overrideNext ??
600-
IntroButton(
601-
child: widget.next!,
602-
style: widget.baseBtnStyle?.merge(widget.nextStyle) ??
603-
widget.nextStyle,
604-
semanticLabel: widget.nextSemantic,
605-
onPressed: !_isScrolling ? next : null,
606-
);
606+
rightBtn = widget.overrideNext != null
607+
? widget.overrideNext!(context, !_isScrolling ? next : null)
608+
: IntroButton(
609+
child: widget.next!,
610+
style: widget.baseBtnStyle?.merge(widget.nextStyle) ??
611+
widget.nextStyle,
612+
semanticLabel: widget.nextSemantic,
613+
onPressed: !_isScrolling ? next : null,
614+
);
607615
}
608616

609617
final pages = widget.pages

0 commit comments

Comments
 (0)