Skip to content

Commit f7a5e5c

Browse files
authored
Merge branch 'master' into master
2 parents 626c0b6 + d838a90 commit f7a5e5c

File tree

2 files changed

+63
-43
lines changed

2 files changed

+63
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ This is the full list:
349349
- This param is required, EXCEPT if you set `showNextButton: false`
350350
- Define pre-made Skip button child (Widget), by adding `skip: Text('Skip')`
351351
- This param is required if you set `showSkipButton: true`
352-
Define pre-made Back button child (Widget), by adding `back: Text('Back')`
352+
- Define pre-made Back button child (Widget), by adding `back: Text('Back')`
353353
- This param is required if you set `showBackButton: true`
354354

355355
#### Use custom buttons

lib/src/introduction_screen.dart

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ library introduction_screen;
33
import 'dart:async';
44
import 'dart:math';
55

6-
import 'package:flutter/material.dart';
7-
86
import 'package:collection/collection.dart';
97
import 'package:dots_indicator/dots_indicator.dart';
8+
import 'package:flutter/material.dart';
109
import 'package:flutter_keyboard_visibility_temp_fork/flutter_keyboard_visibility_temp_fork.dart';
1110

1211
import '/src/helper.dart';
@@ -42,28 +41,32 @@ class IntroductionScreen extends StatefulWidget {
4241

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

4747
/// Skip button child for the pre-made TextButton
4848
final Widget? skip;
4949

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

5455
/// Next button child for the pre-made TextButton
5556
final Widget? next;
5657

5758
/// Override pre-made next button.
5859
/// You can what you want (button, text, image, ...)
59-
final Widget? overrideNext;
60+
final Widget Function(BuildContext context, Function()? onPressed)?
61+
overrideNext;
6062

6163
/// Back button child for the pre-made TextButton
6264
final Widget? back;
6365

6466
/// Override pre-made back button.
6567
/// You can what you want (button, text, image, ...)
66-
final Widget? overrideBack;
68+
final Widget Function(BuildContext context, Function()? onPressed)?
69+
overrideBack;
6770

6871
/// Is the Skip button should be display
6972
///
@@ -96,6 +99,11 @@ class IntroductionScreen extends StatefulWidget {
9699
/// @Default `false`
97100
final bool showBackButton;
98101

102+
/// If the Back button should be display for the first page
103+
///
104+
/// @Default `false`
105+
final bool showFirstBackButton;
106+
99107
/// If a custom Widget should be used instead of the default progress indicator
100108
///
101109
/// @Default `null`
@@ -199,6 +207,9 @@ class IntroductionScreen extends StatefulWidget {
199207
/// Back button semantic label
200208
final String? backSemantic;
201209

210+
/// Progress indicator semantic label
211+
final String Function(int, int)? progressSemantic;
212+
202213
/// Enable or disable content resizing for bottom inset (e.g. keyboard)
203214
///
204215
/// @Default `true`
@@ -299,6 +310,7 @@ class IntroductionScreen extends StatefulWidget {
299310
this.showDoneButton = true,
300311
this.showBottomPart = true,
301312
this.showBackButton = false,
313+
this.showFirstBackButton = false,
302314
this.customProgress,
303315
this.isProgress = true,
304316
this.hideBottomOnKeyboard = false,
@@ -324,6 +336,7 @@ class IntroductionScreen extends StatefulWidget {
324336
this.nextSemantic,
325337
this.doneSemantic,
326338
this.backSemantic,
339+
this.progressSemantic,
327340
this.resizeToAvoidBottomInset = true,
328341
this.controlsPosition = const Position(left: 0, right: 0, bottom: 0),
329342
this.controlsMargin = EdgeInsets.zero,
@@ -558,49 +571,54 @@ class IntroductionScreenState extends State<IntroductionScreen> {
558571
maintainAnimation: true,
559572
// Needs to be true to maintain size
560573
maintainSize: true,
561-
child: widget.overrideSkip ??
562-
IntroButton(
563-
child: widget.skip!,
564-
style: widget.baseBtnStyle?.merge(widget.skipStyle) ??
565-
widget.skipStyle,
566-
semanticLabel: widget.skipSemantic,
567-
onPressed: _onSkip,
568-
),
574+
child: widget.overrideSkip != null
575+
? widget.overrideSkip!(context, _onSkip)
576+
: IntroButton(
577+
child: widget.skip!,
578+
style: widget.baseBtnStyle?.merge(widget.skipStyle) ??
579+
widget.skipStyle,
580+
semanticLabel: widget.skipSemantic,
581+
onPressed: _onSkip,
582+
),
569583
);
570-
} else if (widget.showBackButton &&
571-
getCurrentPage() > 0 &&
572-
widget.canProgress(getCurrentPage())) {
573-
leftBtn = widget.overrideBack ??
574-
IntroButton(
575-
child: widget.back!,
576-
style: widget.baseBtnStyle?.merge(widget.backStyle) ??
577-
widget.backStyle,
578-
semanticLabel: widget.backSemantic,
579-
onPressed: !_isScrolling ? previous : null,
580-
);
584+
} else if ((widget.showFirstBackButton && getCurrentPage() == 0) ||
585+
(widget.showBackButton &&
586+
getCurrentPage() > 0 &&
587+
widget.canProgress(getCurrentPage()))) {
588+
leftBtn = widget.overrideBack != null
589+
? widget.overrideBack!(context, !_isScrolling ? previous : null)
590+
: IntroButton(
591+
child: widget.back!,
592+
style: widget.baseBtnStyle?.merge(widget.backStyle) ??
593+
widget.backStyle,
594+
semanticLabel: widget.backSemantic,
595+
onPressed: !_isScrolling ? previous : null,
596+
);
581597
}
582598

583599
Widget? rightBtn;
584600
if (isLastPage && widget.showDoneButton) {
585-
rightBtn = widget.overrideDone ??
586-
IntroButton(
587-
child: widget.done!,
588-
style: widget.baseBtnStyle?.merge(widget.doneStyle) ??
589-
widget.doneStyle,
590-
semanticLabel: widget.doneSemantic,
591-
onPressed: !_isScrolling ? widget.onDone : null,
592-
);
601+
rightBtn = widget.overrideDone != null
602+
? widget.overrideDone!(context, !_isScrolling ? widget.onDone : null)
603+
: IntroButton(
604+
child: widget.done!,
605+
style: widget.baseBtnStyle?.merge(widget.doneStyle) ??
606+
widget.doneStyle,
607+
semanticLabel: widget.doneSemantic,
608+
onPressed: !_isScrolling ? widget.onDone : null,
609+
);
593610
} else if (!isLastPage &&
594611
widget.showNextButton &&
595612
widget.canProgress(getCurrentPage())) {
596-
rightBtn = widget.overrideNext ??
597-
IntroButton(
598-
child: widget.next!,
599-
style: widget.baseBtnStyle?.merge(widget.nextStyle) ??
600-
widget.nextStyle,
601-
semanticLabel: widget.nextSemantic,
602-
onPressed: !_isScrolling ? next : null,
603-
);
613+
rightBtn = widget.overrideNext != null
614+
? widget.overrideNext!(context, !_isScrolling ? next : null)
615+
: IntroButton(
616+
child: widget.next!,
617+
style: widget.baseBtnStyle?.merge(widget.nextStyle) ??
618+
widget.nextStyle,
619+
semanticLabel: widget.nextSemantic,
620+
onPressed: !_isScrolling ? next : null,
621+
);
604622
}
605623

606624
final pages = widget.pages
@@ -680,7 +698,9 @@ class IntroductionScreenState extends State<IntroductionScreen> {
680698
child: widget.isProgress
681699
? widget.customProgress ??
682700
Semantics(
683-
label:
701+
label: widget.progressSemantic?.call(
702+
getCurrentPage() + 1,
703+
getPagesLength()) ??
684704
"Page ${getCurrentPage() + 1} of ${getPagesLength()}",
685705
excludeSemantics: true,
686706
child: DotsIndicator(

0 commit comments

Comments
 (0)