/
intro_slider.dart
1104 lines (946 loc) · 30.4 KB
/
intro_slider.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dot_animation_enum.dart';
import 'list_rtl_language.dart';
import 'scrollbar_behavior_enum.dart';
import 'slide_object.dart';
class IntroSlider extends StatefulWidget {
// ---------- Slides ----------
/// An array of Slide object
final List<Slide> slides;
/// Background color for all slides
final Color backgroundColorAllSlides;
// ---------- SKIP button ----------
/// Render your own SKIP button
final Widget renderSkipBtn;
/// Width of view wrapper SKIP button
final double widthSkipBtn;
/// Fire when press SKIP button
final Function onSkipPress;
/// Change SKIP to any text you want
final String nameSkipBtn;
/// Style for text at SKIP button
final TextStyle styleNameSkipBtn;
/// Color for SKIP button
final Color colorSkipBtn;
/// Color for Skip button when press
final Color highlightColorSkipBtn;
/// Show or hide SKIP button
final bool isShowSkipBtn;
/// Rounded SKIP button
final double borderRadiusSkipBtn;
// ---------- PREV button ----------
/// Render your own PREV button
final Widget renderPrevBtn;
/// Width of view wrapper PREV button
final double widthPrevBtn;
/// Change PREV to any text you want
final String namePrevBtn;
/// Style for text at PREV button
final TextStyle styleNamePrevBtn;
/// Color for PREV button
final Color colorPrevBtn;
/// Color for PREV button when press
final Color highlightColorPrevBtn;
/// Show or hide PREV button (only visible if skip is hidden)
final bool isShowPrevBtn;
/// Rounded PREV button
final double borderRadiusPrevBtn;
// ---------- NEXT button ----------
/// Render your own NEXT button
final Widget renderNextBtn;
/// Change NEXT to any text you want
final String nameNextBtn;
/// Show or hide NEXT button
final bool isShowNextBtn;
// ---------- DONE button ----------
/// Change DONE to any text you want
final String nameDoneBtn;
/// Render your own DONE button
final Widget renderDoneBtn;
/// Width of view wrapper DONE button
final double widthDoneBtn;
/// Fire when press DONE button
final Function onDonePress;
/// Style for text at DONE button
final TextStyle styleNameDoneBtn;
/// Color for DONE button
final Color colorDoneBtn;
/// Color for DONE button when press
final Color highlightColorDoneBtn;
/// Rounded DONE button
final double borderRadiusDoneBtn;
/// Show or hide DONE button
final bool isShowDoneBtn;
// ---------- Dot indicator ----------
/// Show or hide dot indicator
final bool isShowDotIndicator;
/// Color for dot when passive
final Color colorDot;
/// Color for dot when active
final Color colorActiveDot;
/// Size of each dot
final double sizeDot;
/// Type dots animation
final dotSliderAnimation typeDotAnimation;
// ---------- Tabs ----------
/// Render your own custom tabs
final List<Widget> listCustomTabs;
/// Notify when tab change completed
final Function onTabChangeCompleted;
/// Ref function go to specific tab index
final Function refFuncGoToTab;
// ---------- Behavior ----------
/// Whether or not the slider is scrollable (or controlled only by buttons)
final bool isScrollable;
/// Show or hide status bar
final bool shouldHideStatusBar;
/// The way the vertical scrollbar should behave
final scrollbarBehavior verticalScrollbarBehavior;
// Constructor
IntroSlider({
// Slides
@required this.slides,
this.backgroundColorAllSlides,
// Skip
this.renderSkipBtn,
this.widthSkipBtn,
this.onSkipPress,
this.nameSkipBtn,
this.styleNameSkipBtn,
this.colorSkipBtn,
this.highlightColorSkipBtn,
this.isShowSkipBtn,
this.borderRadiusSkipBtn,
// Prev
this.renderPrevBtn,
this.widthPrevBtn,
this.namePrevBtn,
this.isShowPrevBtn,
this.styleNamePrevBtn,
this.colorPrevBtn,
this.highlightColorPrevBtn,
this.borderRadiusPrevBtn,
// Done
this.renderDoneBtn,
this.widthDoneBtn,
this.onDonePress,
this.nameDoneBtn,
this.colorDoneBtn,
this.highlightColorDoneBtn,
this.borderRadiusDoneBtn,
this.styleNameDoneBtn,
this.isShowDoneBtn,
// Next
this.renderNextBtn,
this.nameNextBtn,
this.isShowNextBtn,
// Dots
this.isShowDotIndicator,
this.colorDot,
this.colorActiveDot,
this.sizeDot,
this.typeDotAnimation,
// Tabs
this.listCustomTabs,
this.onTabChangeCompleted,
this.refFuncGoToTab,
// Behavior
this.isScrollable,
this.shouldHideStatusBar,
this.verticalScrollbarBehavior,
});
@override
IntroSliderState createState() {
return new IntroSliderState(
// Slides
slides: this.slides,
backgroundColorAllSlides: this.backgroundColorAllSlides,
// Skip
renderSkipBtn: this.renderSkipBtn,
widthSkipBtn: this.widthSkipBtn,
onSkipPress: this.onSkipPress,
nameSkipBtn: this.nameSkipBtn,
styleNameSkipBtn: this.styleNameSkipBtn,
colorSkipBtn: this.colorSkipBtn,
highlightColorSkipBtn: this.highlightColorSkipBtn,
isShowSkipBtn: this.isShowSkipBtn,
borderRadiusSkipBtn: this.borderRadiusSkipBtn,
// Prev
renderPrevBtn: this.renderPrevBtn,
widthPrevBtn: this.widthPrevBtn,
namePrevBtn: this.namePrevBtn,
isShowPrevBtn: this.isShowPrevBtn,
styleNamePrevBtn: this.styleNamePrevBtn,
colorPrevBtn: this.colorPrevBtn,
highlightColorPrevBtn: this.highlightColorPrevBtn,
borderRadiusPrevBtn: this.borderRadiusPrevBtn,
// Done
renderDoneBtn: this.renderDoneBtn,
widthDoneBtn: this.widthDoneBtn,
onDonePress: this.onDonePress,
nameDoneBtn: this.nameDoneBtn,
styleNameDoneBtn: this.styleNameDoneBtn,
colorDoneBtn: this.colorDoneBtn,
highlightColorDoneBtn: this.highlightColorDoneBtn,
borderRadiusDoneBtn: this.borderRadiusDoneBtn,
isShowDoneBtn: this.isShowDoneBtn,
// Next
renderNextBtn: this.renderNextBtn,
nameNextBtn: this.nameNextBtn,
isShowNextBtn: this.isShowNextBtn,
// Dots
isShowDotIndicator: this.isShowDotIndicator,
colorDot: this.colorDot,
colorActiveDot: this.colorActiveDot,
sizeDot: this.sizeDot,
typeDotAnimation: this.typeDotAnimation,
// Tabs
listCustomTabs: this.listCustomTabs,
onTabChangeCompleted: this.onTabChangeCompleted,
refFuncGoToTab: this.refFuncGoToTab,
// Behavior
isScrollable: this.isScrollable,
shouldHideStatusBar: this.shouldHideStatusBar,
verticalScrollbarBehavior:
this.verticalScrollbarBehavior ?? scrollbarBehavior.HIDE,
);
}
}
class IntroSliderState extends State<IntroSlider>
with SingleTickerProviderStateMixin {
/// Default values
static TextStyle defaultBtnNameTextStyle = TextStyle(color: Colors.white);
static double defaultBtnBorderRadius = 30.0;
static Color defaultBtnColor = Colors.transparent;
static Color defaultBtnHighlightColor = Colors.white.withOpacity(0.3);
// ---------- Slides ----------
/// An array of Slide object
final List<Slide> slides;
/// Background color for all slides
Color backgroundColorAllSlides;
// ---------- SKIP button ----------
/// Render your own SKIP button
Widget renderSkipBtn;
/// Width of view wrapper SKIP button
double widthSkipBtn;
/// Fire when press SKIP button
Function onSkipPress;
/// Change SKIP to any text you want
String nameSkipBtn;
/// Style for text at SKIP button
TextStyle styleNameSkipBtn;
/// Color for SKIP button
Color colorSkipBtn;
/// Color for SKIP button when press
Color highlightColorSkipBtn;
/// Show or hide SKIP button
bool isShowSkipBtn;
/// Rounded SKIP button
double borderRadiusSkipBtn;
// ---------- PREV button ----------
/// Render your own PREV button
Widget renderPrevBtn;
/// Change PREV to any text you want
String namePrevBtn;
/// Style for text at PREV button
TextStyle styleNamePrevBtn;
/// Color for PREV button
Color colorPrevBtn;
/// Width of view wrapper PREV button
double widthPrevBtn;
/// Color for PREV button when press
Color highlightColorPrevBtn;
/// Show or hide PREV button
bool isShowPrevBtn;
/// Rounded PREV button
double borderRadiusPrevBtn;
// ---------- DONE button ----------
/// Render your own DONE button
Widget renderDoneBtn;
/// Width of view wrapper DONE button
double widthDoneBtn;
/// Fire when press DONE button
Function onDonePress;
/// Change DONE to any text you want
String nameDoneBtn;
/// Style for text at DONE button
TextStyle styleNameDoneBtn;
/// Color for DONE button
Color colorDoneBtn;
/// Color for DONE button when press
Color highlightColorDoneBtn;
/// Rounded DONE button
double borderRadiusDoneBtn;
/// Show or hide DONE button
bool isShowDoneBtn;
// ---------- NEXT button ----------
/// Render your own NEXT button
Widget renderNextBtn;
/// Change NEXT to any text you want
String nameNextBtn;
/// Show or hide NEXT button
bool isShowNextBtn;
// ---------- Dot indicator ----------
/// Show or hide dot indicator
bool isShowDotIndicator = true;
/// Color for dot when passive
Color colorDot;
/// Color for dot when active
Color colorActiveDot;
/// Size of each dot
double sizeDot = 8.0;
/// Type dots animation
dotSliderAnimation typeDotAnimation;
// ---------- Tabs ----------
/// List custom tabs
List<Widget> listCustomTabs;
/// Notify when tab change completed
Function onTabChangeCompleted;
/// Ref function go to specific tab index
Function refFuncGoToTab;
// ---------- Behavior ----------
/// Allow the slider to scroll
bool isScrollable;
/// Show or hide status bar
bool shouldHideStatusBar;
/// The way the vertical scrollbar should behave
final scrollbarBehavior verticalScrollbarBehavior;
// Constructor
IntroSliderState({
// List slides
@required this.slides,
@required this.backgroundColorAllSlides,
// Skip button
@required this.renderSkipBtn,
@required this.widthSkipBtn,
@required this.onSkipPress,
@required this.nameSkipBtn,
@required this.styleNameSkipBtn,
@required this.colorSkipBtn,
@required this.highlightColorSkipBtn,
@required this.isShowSkipBtn,
@required this.borderRadiusSkipBtn,
// Prev button
@required this.widthPrevBtn,
@required this.isShowPrevBtn,
@required this.namePrevBtn,
@required this.renderPrevBtn,
@required this.styleNamePrevBtn,
@required this.colorPrevBtn,
@required this.highlightColorPrevBtn,
@required this.borderRadiusPrevBtn,
// Done button
@required this.renderDoneBtn,
@required this.widthDoneBtn,
@required this.onDonePress,
@required this.nameDoneBtn,
@required this.styleNameDoneBtn,
@required this.colorDoneBtn,
@required this.highlightColorDoneBtn,
@required this.borderRadiusDoneBtn,
@required this.isShowDoneBtn,
// Next button
@required this.nameNextBtn,
@required this.renderNextBtn,
@required this.isShowNextBtn,
// Dot indicator
@required this.isShowDotIndicator,
@required this.colorDot,
@required this.colorActiveDot,
@required this.sizeDot,
@required this.typeDotAnimation,
// Tabs
@required this.listCustomTabs,
@required this.onTabChangeCompleted,
@required this.refFuncGoToTab,
// Behavior
@required this.isScrollable,
@required this.shouldHideStatusBar,
@required this.verticalScrollbarBehavior,
});
TabController tabController;
List<Widget> tabs = new List();
List<Widget> dots = new List();
List<double> sizeDots = new List();
List<double> opacityDots = new List();
List<ScrollController> scrollControllers = new List();
// For DOT_MOVEMENT
double marginLeftDotFocused = 0;
double marginRightDotFocused = 0;
// For SIZE_TRANSITION
double currentAnimationValue = 0;
int currentTabIndex = 0;
@override
void initState() {
super.initState();
tabController = new TabController(length: slides.length, vsync: this);
tabController.addListener(() {
if (tabController.indexIsChanging) {
currentTabIndex = tabController.previousIndex;
} else {
currentTabIndex = tabController.index;
}
currentAnimationValue = tabController.animation.value;
if (this.onTabChangeCompleted != null) {
this.onTabChangeCompleted(tabController.index);
}
});
// Send reference function goToTab to parent
if (this.refFuncGoToTab != null) {
this.refFuncGoToTab(this.goToTab);
}
// Dot animation
if (sizeDot == null) {
sizeDot = 8.0;
}
double initValueMarginRight = (sizeDot * 2) * (slides.length - 1);
if (typeDotAnimation == null) {
typeDotAnimation = dotSliderAnimation.DOT_MOVEMENT;
}
switch (typeDotAnimation) {
case dotSliderAnimation.DOT_MOVEMENT:
for (int i = 0; i < slides.length; i++) {
sizeDots.add(sizeDot);
opacityDots.add(1.0);
}
marginRightDotFocused = initValueMarginRight;
break;
case dotSliderAnimation.SIZE_TRANSITION:
for (int i = 0; i < slides.length; i++) {
if (i == 0) {
sizeDots.add(sizeDot * 1.5);
opacityDots.add(1.0);
} else {
sizeDots.add(sizeDot);
opacityDots.add(0.5);
}
}
}
tabController.animation.addListener(() {
this.setState(() {
switch (typeDotAnimation) {
case dotSliderAnimation.DOT_MOVEMENT:
marginLeftDotFocused = tabController.animation.value * sizeDot * 2;
marginRightDotFocused = initValueMarginRight -
tabController.animation.value * sizeDot * 2;
break;
case dotSliderAnimation.SIZE_TRANSITION:
if (tabController.animation.value == currentAnimationValue) {
break;
}
double diffValueAnimation =
(tabController.animation.value - currentAnimationValue).abs();
int diffValueIndex = (currentTabIndex - tabController.index).abs();
// When press skip button
if (tabController.indexIsChanging &&
(tabController.index - tabController.previousIndex).abs() > 1) {
if (diffValueAnimation < 1.0) {
diffValueAnimation = 1.0;
}
sizeDots[currentTabIndex] = sizeDot * 1.5 -
(sizeDot / 2) * (1 - (diffValueIndex - diffValueAnimation));
sizeDots[tabController.index] = sizeDot +
(sizeDot / 2) * (1 - (diffValueIndex - diffValueAnimation));
opacityDots[currentTabIndex] =
1.0 - (diffValueAnimation / diffValueIndex) / 2;
opacityDots[tabController.index] =
0.5 + (diffValueAnimation / diffValueIndex) / 2;
} else {
if (tabController.animation.value > currentAnimationValue) {
// Swipe left
sizeDots[currentTabIndex] =
sizeDot * 1.5 - (sizeDot / 2) * diffValueAnimation;
sizeDots[currentTabIndex + 1] =
sizeDot + (sizeDot / 2) * diffValueAnimation;
opacityDots[currentTabIndex] = 1.0 - diffValueAnimation / 2;
opacityDots[currentTabIndex + 1] = 0.5 + diffValueAnimation / 2;
} else {
// Swipe right
sizeDots[currentTabIndex] =
sizeDot * 1.5 - (sizeDot / 2) * diffValueAnimation;
sizeDots[currentTabIndex - 1] =
sizeDot + (sizeDot / 2) * diffValueAnimation;
opacityDots[currentTabIndex] = 1.0 - diffValueAnimation / 2;
opacityDots[currentTabIndex - 1] = 0.5 + diffValueAnimation / 2;
}
}
break;
}
});
});
// Dot indicator
if (isShowDotIndicator == null) {
isShowDotIndicator = true;
}
if (colorDot == null) {
colorDot = Color(0x80000000);
}
if (colorActiveDot == null) {
colorActiveDot = colorDot;
}
if (isScrollable == null) {
isScrollable = true;
}
setupButtonDefaultValues();
if (this.listCustomTabs == null) {
renderListTabs();
} else {
tabs = this.listCustomTabs;
}
}
void setupButtonDefaultValues() {
// Skip button
if (onSkipPress == null) {
onSkipPress = () {
if (!this.isAnimating(tabController.animation.value)) {
tabController.animateTo(slides.length - 1);
}
};
}
if (isShowSkipBtn == null) {
isShowSkipBtn = true;
}
if (styleNameSkipBtn == null) {
styleNameSkipBtn = defaultBtnNameTextStyle;
}
if (nameSkipBtn == null) {
nameSkipBtn = "SKIP";
}
if (renderSkipBtn == null) {
renderSkipBtn = Text(
nameSkipBtn,
style: styleNameSkipBtn,
);
}
if (colorSkipBtn == null) {
colorSkipBtn = defaultBtnColor;
}
if (highlightColorSkipBtn == null) {
highlightColorSkipBtn = defaultBtnHighlightColor;
}
if (borderRadiusSkipBtn == null) {
borderRadiusSkipBtn = defaultBtnBorderRadius;
}
// Prev button
if (isShowPrevBtn == null || isShowSkipBtn) {
isShowPrevBtn = false;
}
if (styleNamePrevBtn == null) {
styleNamePrevBtn = defaultBtnNameTextStyle;
}
if (namePrevBtn == null) {
namePrevBtn = "PREV";
}
if (renderPrevBtn == null) {
renderPrevBtn = Text(
namePrevBtn,
style: styleNamePrevBtn,
);
}
if (colorPrevBtn == null) {
colorPrevBtn = defaultBtnColor;
}
if (highlightColorPrevBtn == null) {
highlightColorPrevBtn = defaultBtnHighlightColor;
}
if (borderRadiusPrevBtn == null) {
borderRadiusPrevBtn = defaultBtnBorderRadius;
}
if (isShowDoneBtn == null) {
isShowDoneBtn = true;
}
if (isShowNextBtn == null) {
isShowNextBtn = true;
}
// Done button
if (onDonePress == null) {
onDonePress = () {};
}
if (styleNameDoneBtn == null) {
styleNameDoneBtn = defaultBtnNameTextStyle;
}
if (nameDoneBtn == null) {
nameDoneBtn = "DONE";
}
if (renderDoneBtn == null) {
renderDoneBtn = Text(
nameDoneBtn,
style: styleNameDoneBtn,
);
}
if (colorDoneBtn == null) {
colorDoneBtn = defaultBtnColor;
}
if (highlightColorDoneBtn == null) {
highlightColorDoneBtn = defaultBtnHighlightColor;
}
if (borderRadiusDoneBtn == null) {
borderRadiusDoneBtn = defaultBtnBorderRadius;
}
// Next button
if (nameNextBtn == null) {
nameNextBtn = "NEXT";
}
if (renderNextBtn == null) {
renderNextBtn = Text(
nameNextBtn,
style: styleNameDoneBtn,
);
}
}
void goToTab(index) {
if (index < tabController.length) {
tabController.animateTo(index);
}
}
@override
void dispose() {
super.dispose();
tabController.dispose();
}
// Checking if tab is animating
bool isAnimating(value) {
return tabController.animation.value -
tabController.animation.value.truncate() !=
0;
}
bool isRTLLanguage(language) {
return rtlLanguages.contains(language);
}
@override
Widget build(BuildContext context) {
// Full screen view
if (shouldHideStatusBar == true) {
SystemChrome.setEnabledSystemUIOverlays([]);
}
return Scaffold(
body: DefaultTabController(
length: slides.length,
child: Stack(
children: <Widget>[
TabBarView(
children: tabs,
controller: tabController,
physics: isScrollable
? ScrollPhysics()
: NeverScrollableScrollPhysics(),
),
renderBottom(),
],
),
),
backgroundColor: this.backgroundColorAllSlides ?? Colors.transparent,
);
}
Widget buildSkipButton() {
if (tabController.index + 1 == slides.length) {
return Container(width: MediaQuery.of(context).size.width / 4);
} else {
return FlatButton(
onPressed: onSkipPress,
child: renderSkipBtn,
color: colorSkipBtn,
highlightColor: highlightColorSkipBtn,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(borderRadiusSkipBtn)),
);
}
}
Widget buildDoneButton() {
return FlatButton(
onPressed: onDonePress,
child: renderDoneBtn,
color: colorDoneBtn,
highlightColor: highlightColorDoneBtn,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(borderRadiusDoneBtn)),
);
}
Widget buildPrevButton() {
if (tabController.index == 0) {
return Container(width: MediaQuery.of(context).size.width / 4);
} else {
return FlatButton(
onPressed: () {
if (!this.isAnimating(tabController.animation.value)) {
tabController.animateTo(tabController.index - 1);
}
},
child: renderPrevBtn,
color: colorPrevBtn,
highlightColor: highlightColorPrevBtn,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(borderRadiusPrevBtn)),
);
}
}
Widget buildNextButton() {
return FlatButton(
onPressed: () {
if (!this.isAnimating(tabController.animation.value)) {
tabController.animateTo(tabController.index + 1);
}
},
child: renderNextBtn,
color: colorDoneBtn,
highlightColor: highlightColorDoneBtn,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(borderRadiusDoneBtn)),
);
}
Widget renderBottom() {
return Positioned(
child: Row(
children: <Widget>[
// Skip button
Container(
alignment: Alignment.center,
child: isShowSkipBtn
? buildSkipButton()
: (isShowPrevBtn ? buildPrevButton() : Container()),
width: isShowSkipBtn
? widthSkipBtn ?? MediaQuery.of(context).size.width / 4
: (isShowPrevBtn
? widthPrevBtn
: MediaQuery.of(context).size.width / 4),
),
// Dot indicator
Flexible(
child: isShowDotIndicator
? Container(
child: Stack(
children: <Widget>[
Row(
children: this.renderListDots(),
mainAxisAlignment: MainAxisAlignment.center,
),
typeDotAnimation == dotSliderAnimation.DOT_MOVEMENT
? Center(
child: Container(
decoration: BoxDecoration(
color: colorActiveDot,
borderRadius:
BorderRadius.circular(sizeDot / 2)),
width: sizeDot,
height: sizeDot,
margin: EdgeInsets.only(
left: this.isRTLLanguage(
Localizations.localeOf(context)
.languageCode)
? marginRightDotFocused
: marginLeftDotFocused,
right: this.isRTLLanguage(
Localizations.localeOf(context)
.languageCode)
? marginLeftDotFocused
: marginRightDotFocused),
),
)
: Container()
],
),
)
: Container(),
),
// Next, Done button
Container(
alignment: Alignment.center,
child: tabController.index + 1 == slides.length
? isShowDoneBtn ? buildDoneButton() : Container()
: isShowNextBtn ? buildNextButton() : Container(),
width: widthDoneBtn ?? MediaQuery.of(context).size.width / 4,
height: 50,
),
],
),
bottom: 10.0,
left: 10.0,
right: 10.0,
);
}
List<Widget> renderListTabs() {
for (int i = 0; i < slides.length; i++) {
final scrollController = ScrollController();
scrollControllers.add(scrollController);
tabs.add(
renderTab(
scrollController,
slides[i].widgetTitle,
slides[i].title,
slides[i].maxLineTitle,
slides[i].styleTitle,
slides[i].marginTitle,
slides[i].widgetDescription,
slides[i].description,
slides[i].maxLineTextDescription,
slides[i].styleDescription,
slides[i].marginDescription,
slides[i].pathImage,
slides[i].widthImage,
slides[i].heightImage,
slides[i].foregroundImageFit,
slides[i].centerWidget,
slides[i].onCenterItemPress,
slides[i].backgroundColor,
slides[i].colorBegin,
slides[i].colorEnd,
slides[i].directionColorBegin,
slides[i].directionColorEnd,
slides[i].backgroundImage,
slides[i].backgroundImageFit,
slides[i].backgroundOpacity,
slides[i].backgroundOpacityColor,
slides[i].backgroundBlendMode,
),
);
}
return tabs;
}
Widget renderTab(
ScrollController scrollController,
// Title
Widget widgetTitle,
String title,
int maxLineTitle,
TextStyle styleTitle,
EdgeInsets marginTitle,
// Description
Widget widgetDescription,
String description,
int maxLineTextDescription,
TextStyle styleDescription,
EdgeInsets marginDescription,
// Image
String pathImage,
double widthImage,
double heightImage,
BoxFit foregroundImageFit,
// Center Widget
Widget centerWidget,
Function onCenterItemPress,
// Background color
Color backgroundColor,
Color colorBegin,
Color colorEnd,
AlignmentGeometry directionColorBegin,
AlignmentGeometry directionColorEnd,
// Background image
String backgroundImage,
BoxFit backgroundImageFit,
double backgroundOpacity,
Color backgroundOpacityColor,
BlendMode backgroundBlendMode,
) {
final listView = ListView(
controller: scrollController,
children: <Widget>[
Container(
// Title
child: widgetTitle ??
Text(
title ?? "",
style: styleTitle ??
TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,