@@ -2,16 +2,18 @@ import 'package:flutter/material.dart';
22import 'package:intro_views_flutter/Constants/constants.dart' ;
33import 'package:intro_views_flutter/Models/page_button_view_model.dart' ;
44
5- /// Skip button class
5+ /// Skip, Next, and Back button class
66
7- class SkipButton extends StatelessWidget {
7+ class DefaultButton extends StatelessWidget {
88 //callback for skip button
99 final VoidCallback onTap;
10+
1011 //view model
1112 final PageButtonViewModel pageButtonViewModel;
1213 final Widget child;
14+
1315 //Constructor
14- SkipButton ({
16+ DefaultButton ({
1517 this .onTap,
1618 this .pageButtonViewModel,
1719 this .child,
@@ -50,9 +52,11 @@ class SkipButton extends StatelessWidget {
5052class DoneButton extends StatelessWidget {
5153 //Callback
5254 final VoidCallback onTap;
55+
5356 //View Model
5457 final PageButtonViewModel pageButtonViewModel;
5558 final Widget child;
59+
5660 //Constructor
5761 DoneButton ({
5862 this .onTap,
@@ -86,34 +90,116 @@ class DoneButton extends StatelessWidget {
8690
8791class PageIndicatorButtons extends StatelessWidget {
8892 //Some variables
89- final int acitvePageIndex ;
93+ final int activePageIndex ;
9094 final int totalPages;
9195 final VoidCallback onPressedDoneButton; //Callback for Done Button
96+ final VoidCallback onPressedNextButton;
97+ final VoidCallback onPressedBackButton;
9298 final VoidCallback onPressedSkipButton; //Callback for Skip Button
9399 final SlideDirection slideDirection;
94100 final double slidePercent;
95101 final bool showSkipButton;
102+ final bool showNextButton;
103+ final bool showBackButton;
96104
97105 final Widget doneText;
98106 final Widget skipText;
107+ final Widget nextText;
108+ final Widget backText;
99109 final TextStyle textStyle;
100110
101111 final bool doneButtonPersist;
102112
113+ Widget _getDoneORNextButton () {
114+ if ((activePageIndex < totalPages - 1 ||
115+ (activePageIndex == totalPages - 1 &&
116+ slideDirection == SlideDirection .leftToRight)) &&
117+ showNextButton) {
118+ return DefaultButton (
119+ child: nextText,
120+ onTap: onPressedNextButton,
121+ pageButtonViewModel: PageButtonViewModel (
122+ //View Model
123+ activePageIndex: activePageIndex,
124+ totalPages: totalPages,
125+ slidePercent: slidePercent,
126+ slideDirection: slideDirection,
127+ ),
128+ );
129+ } else if (activePageIndex == totalPages - 1 ||
130+ (activePageIndex == totalPages - 2 &&
131+ slideDirection == SlideDirection .rightToLeft ||
132+ doneButtonPersist)) {
133+ return DoneButton (
134+ child: doneText,
135+ onTap: onPressedDoneButton,
136+ pageButtonViewModel: PageButtonViewModel (
137+ //view Model
138+ activePageIndex: activePageIndex,
139+ totalPages: totalPages,
140+ slidePercent: doneButtonPersist ? 0.0 : slidePercent,
141+ slideDirection: slideDirection,
142+ ),
143+ );
144+ } else {
145+ return Container ();
146+ }
147+ }
148+
149+ Widget _getSkipORBackButton () {
150+ if (activePageIndex <= totalPages &&
151+ activePageIndex >= 1 &&
152+ showBackButton) {
153+ return DefaultButton (
154+ child: backText,
155+ onTap: onPressedBackButton,
156+ pageButtonViewModel: PageButtonViewModel (
157+ //View Model
158+ activePageIndex: activePageIndex,
159+ totalPages: totalPages,
160+ slidePercent: slidePercent,
161+ slideDirection: slideDirection,
162+ ),
163+ );
164+ } else if ((activePageIndex < totalPages - 1 ||
165+ (activePageIndex == totalPages - 1 &&
166+ slideDirection == SlideDirection .leftToRight)) &&
167+ showSkipButton) {
168+ return DefaultButton (
169+ child: skipText,
170+ onTap: onPressedSkipButton,
171+ pageButtonViewModel: PageButtonViewModel (
172+ //View Model
173+ activePageIndex: activePageIndex,
174+ totalPages: totalPages,
175+ slidePercent: slidePercent,
176+ slideDirection: slideDirection,
177+ ),
178+ );
179+ } else {
180+ return Container ();
181+ }
182+ }
183+
103184 //Constructor
104- PageIndicatorButtons ({
105- @required this .acitvePageIndex,
106- @required this .totalPages,
107- this .onPressedDoneButton,
108- this .slideDirection,
109- this .slidePercent,
110- this .onPressedSkipButton,
111- this .showSkipButton = true ,
112- this .skipText,
113- this .doneText,
114- this .textStyle,
115- this .doneButtonPersist,
116- });
185+ PageIndicatorButtons (
186+ {@required this .activePageIndex,
187+ @required this .totalPages,
188+ this .onPressedDoneButton,
189+ this .slideDirection,
190+ this .slidePercent,
191+ this .onPressedSkipButton,
192+ this .onPressedNextButton,
193+ this .onPressedBackButton,
194+ this .showSkipButton,
195+ this .skipText,
196+ this .nextText,
197+ this .doneText,
198+ this .textStyle,
199+ this .doneButtonPersist,
200+ this .showNextButton = true ,
201+ this .showBackButton = true ,
202+ this .backText});
117203
118204 @override
119205 Widget build (BuildContext context) {
@@ -129,43 +215,13 @@ class PageIndicatorButtons extends StatelessWidget {
129215 mainAxisSize: MainAxisSize .max,
130216 children: < Widget > [
131217 Padding (
132- padding: const EdgeInsets .only (bottom: 10.0 ),
133- child: ((acitvePageIndex < totalPages - 1 ||
134- (acitvePageIndex == totalPages - 1 &&
135- slideDirection == SlideDirection .leftToRight)) &&
136- showSkipButton)
137- ? SkipButton (
138- child: skipText,
139- onTap: onPressedSkipButton,
140- pageButtonViewModel: PageButtonViewModel (
141- //View Model
142- activePageIndex: acitvePageIndex,
143- totalPages: totalPages,
144- slidePercent: slidePercent,
145- slideDirection: slideDirection,
146- ),
147- )
148- : Container (), //Row
149- ), //Padding
218+ padding: const EdgeInsets .only (bottom: 10.0 ),
219+ child: _getSkipORBackButton () //Row
220+ ), //Padding
150221 Padding (
151- padding: const EdgeInsets .only (bottom: 10.0 ),
152- child: (acitvePageIndex == totalPages - 1 ||
153- (acitvePageIndex == totalPages - 2 &&
154- slideDirection == SlideDirection .rightToLeft ||
155- doneButtonPersist))
156- ? DoneButton (
157- child: doneText,
158- onTap: onPressedDoneButton,
159- pageButtonViewModel: PageButtonViewModel (
160- //view Model
161- activePageIndex: acitvePageIndex,
162- totalPages: totalPages,
163- slidePercent: doneButtonPersist ? 0.0 : slidePercent,
164- slideDirection: slideDirection,
165- ),
166- )
167- : Container (), //Row
168- ),
222+ padding: const EdgeInsets .only (bottom: 10.0 ),
223+ child: _getDoneORNextButton () //Row
224+ )
169225 ],
170226 ),
171227 ),
0 commit comments