Skip to content

Commit d646f8f

Browse files
committed
Merge branch 'taljacobson-defaultTextStyles'
2 parents a7cf5b1 + 293ca9a commit d646f8f

File tree

8 files changed

+234
-194
lines changed

8 files changed

+234
-194
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.dart_tool/
3+
.idea
34

45
.packages
56
.pub/

.idea/workspace.xml

Lines changed: 107 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ You should then run `flutter packages get` in your terminal so as to get the pac
7474
//Void Callback
7575
},
7676
showSkipButton: true,
77-
pageButtonFontFamily: "Regular",
78-
pageButtonsColor: Colors.white,
79-
pageButtonTextSize: 18.0,
77+
pageButtonTextStyles: new TextStyle(
78+
color: Colors.white,
79+
fontSize: 18.0,
80+
fontFamily: "Regular",
81+
),
82+
8083
);
8184
```
8285
For further usage refer the [`example`](https://github.com/aagarwal1012/IntroViews-Flutter/tree/master/example/lib) available.
@@ -111,12 +114,12 @@ You should then run `flutter packages get` in your terminal so as to get the pac
111114
| :---------------- | :------------------------------ | :----------------------------------------------------------- | :-----------: |
112115
| pages | List<PageViewMode> | Set the pages of the intro screen. | Null |
113116
| onTapDoneButton | VoidCallback | Method executes on tapping done button. | Null |
114-
| pageButtonColor | Color | Set the color of skip and done buttons. | Colors.white |
115117
| showSkipButton | Bool | Show the skip button at the bottom of page. | true |
116118
| pageButtonTextSize | Double | Set the button text size. | 18.0 |
117119
| pageButtonFontFamily | String | Set the font of button text. | Default |
118120
| onTapSkipButton | VoidCallback | Method executes on tapping skip button. | null |
119-
121+
| pageButtonTextStyles | TextStyle | Configure TextStyle for skip, done buttons, overrides pageButtonFontFamily, pageButtonsColor, pageButtonTextSize. | fontSize: 18.0, color: Color(0x88FFFFFF) |
122+
120123
For help on editing package code, view the [flutter documentation](https://flutter.io/developing-packages/).
121124

122125
# Want to contribute !

example/lib/main.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ class App extends StatelessWidget {
8080
},
8181
showSkipButton:
8282
true, //Whether you want to show the skip button or not.
83-
pageButtonsColor: Colors.white,
84-
pageButtonTextSize: 18.0,
83+
pageButtonTextStyles: TextStyle(
84+
color: Colors.white,
85+
fontSize: 18.0,
86+
),
8587
), //IntroViewsFlutter
8688
), //Builder
8789
); //Material App

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ packages:
129129
path: ".."
130130
relative: true
131131
source: path
132-
version: "1.0.3"
132+
version: "1.0.2"
133133
io:
134134
dependency: transitive
135135
description:
@@ -374,5 +374,5 @@ packages:
374374
source: hosted
375375
version: "2.1.13"
376376
sdks:
377-
dart: ">=2.0.0-dev.52.0 <=2.0.0-dev.54.0.flutter-46ab040e58"
377+
dart: ">=2.0.0-dev.52.0 <=2.0.0-dev.58.0.flutter-f981f09760"
378378
flutter: ">=0.1.4 <2.0.0"
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:flutter/material.dart';
21
import 'package:intro_views_flutter/Constants/constants.dart';
32

43
/// This is view model for the skip and done buttons.
@@ -8,17 +7,11 @@ class PageButtonViewModel {
87
final int totalPages;
98
final int activePageIndex;
109
final SlideDirection slideDirection;
11-
final String fontFamily;
12-
final double pageButtonTextSize;
13-
final Color pageButtonColor;
1410

1511
PageButtonViewModel({
1612
this.slidePercent,
1713
this.totalPages,
1814
this.activePageIndex,
1915
this.slideDirection,
20-
this.fontFamily,
21-
this.pageButtonTextSize = 18.0,
22-
this.pageButtonColor = Colors.white,
2316
});
2417
}

lib/UI/page_indicator_buttons.dart

Lines changed: 52 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SkipButton extends StatelessWidget {
2020
Widget build(BuildContext context) {
2121
//Calculating opacity to create a fade in effect
2222
double opacity = 1.0;
23-
23+
final TextStyle style = DefaultTextStyle.of(context).style;
2424
if (pageButtonViewModel.activePageIndex ==
2525
pageButtonViewModel.totalPages - 2 &&
2626
pageButtonViewModel.slideDirection == SlideDirection.rightToLeft) {
@@ -37,11 +37,7 @@ class SkipButton extends StatelessWidget {
3737
opacity: opacity,
3838
child: new Text(
3939
"SKIP",
40-
style: new TextStyle(
41-
color: pageButtonViewModel.pageButtonColor,
42-
fontSize: pageButtonViewModel.pageButtonTextSize,
43-
fontFamily: pageButtonViewModel.fontFamily,
44-
), //TextStyle
40+
style: style, //TextStyle
4541
), //Text
4642
), //Opacity
4743
); //FlatButton
@@ -66,7 +62,7 @@ class DoneButton extends StatelessWidget {
6662
Widget build(BuildContext context) {
6763
//Calculating opacity so as to create a fade in effect
6864
double opacity = 1.0;
69-
65+
final TextStyle style = DefaultTextStyle.of(context).style;
7066
if (pageButtonViewModel.activePageIndex ==
7167
pageButtonViewModel.totalPages - 1 &&
7268
pageButtonViewModel.slideDirection == SlideDirection.leftToRight) {
@@ -79,11 +75,7 @@ class DoneButton extends StatelessWidget {
7975
opacity: opacity,
8076
child: new Text(
8177
"DONE",
82-
style: new TextStyle(
83-
color: pageButtonViewModel.pageButtonColor,
84-
fontSize: pageButtonViewModel.pageButtonTextSize,
85-
fontFamily: pageButtonViewModel.fontFamily,
86-
), //TextStyle
78+
style: style, //TextStyle
8779
), //Text
8880
), //Opacity
8981
); //FlatButton
@@ -98,10 +90,7 @@ class PageIndicatorButtons extends StatelessWidget {
9890
final VoidCallback onPressedSkipButton; //Callback for Skip Button
9991
final SlideDirection slideDirection;
10092
final double slidePercent;
101-
final Color pageButtonsColor;
10293
final bool showSkipButton;
103-
final String fontFamily;
104-
final double pageButtonTextSize;
10594

10695
//Constructor
10796
PageIndicatorButtons({
@@ -111,81 +100,58 @@ class PageIndicatorButtons extends StatelessWidget {
111100
this.slideDirection,
112101
this.slidePercent,
113102
this.onPressedSkipButton,
114-
this.pageButtonsColor = const Color(0x88FFFFFF),
115103
this.showSkipButton = true,
116-
this.fontFamily,
117-
this.pageButtonTextSize = 18.0,
118104
});
119105

120106
@override
121107
Widget build(BuildContext context) {
122-
return new Stack(
123-
children: <Widget>[
124-
new Column(
125-
mainAxisAlignment: MainAxisAlignment.start,
126-
children: <Widget>[
127-
new Expanded(child: new Container()),
128-
new Padding(
129-
padding: const EdgeInsets.only(bottom: 10.0),
130-
child: new Row(
131-
mainAxisAlignment: MainAxisAlignment.start,
132-
children: <Widget>[
133-
((acitvePageIndex < totalPages - 1 ||
134-
(acitvePageIndex == totalPages - 1 &&
135-
slideDirection ==
136-
SlideDirection.leftToRight)) &&
137-
showSkipButton)
138-
? new SkipButton(
139-
onTap: onPressedSkipButton,
140-
pageButtonViewModel: new PageButtonViewModel(
141-
//View Model
142-
activePageIndex: acitvePageIndex,
143-
totalPages: totalPages,
144-
slidePercent: slidePercent,
145-
slideDirection: slideDirection,
146-
fontFamily: fontFamily,
147-
pageButtonColor: pageButtonsColor,
148-
pageButtonTextSize: pageButtonTextSize,
149-
),
150-
)
151-
: new Container(),
152-
],
153-
), //Row
154-
), //Padding
155-
],
156-
), //Column
157-
new Column(
158-
mainAxisAlignment: MainAxisAlignment.end,
159-
children: <Widget>[
160-
new Expanded(child: new Container()),
161-
new Padding(
162-
padding: const EdgeInsets.only(bottom: 10.0),
163-
child: new Row(
164-
mainAxisAlignment: MainAxisAlignment.end,
165-
children: <Widget>[
166-
(acitvePageIndex == totalPages - 1 ||
167-
(acitvePageIndex == totalPages - 2 &&
168-
slideDirection == SlideDirection.rightToLeft))
169-
? new DoneButton(
170-
onTap: onPressedDoneButton,
171-
pageButtonViewModel: new PageButtonViewModel(
172-
//view Model
173-
activePageIndex: acitvePageIndex,
174-
totalPages: totalPages,
175-
slidePercent: slidePercent,
176-
slideDirection: slideDirection,
177-
fontFamily: fontFamily,
178-
pageButtonColor: pageButtonsColor,
179-
pageButtonTextSize: pageButtonTextSize,
180-
),
181-
)
182-
: new Container(),
183-
],
184-
), //Row
185-
), //Padding
186-
],
187-
), //Column
188-
],
189-
); //Stack
108+
return Positioned(
109+
left: 0.0,
110+
right: 0.0,
111+
bottom: 0.0,
112+
child: new Row(
113+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
114+
crossAxisAlignment: CrossAxisAlignment.center,
115+
mainAxisSize: MainAxisSize.max,
116+
children: <Widget>[
117+
new Padding(
118+
padding: const EdgeInsets.only(bottom: 10.0),
119+
child: ((acitvePageIndex < totalPages - 1 ||
120+
(acitvePageIndex == totalPages - 1 &&
121+
slideDirection == SlideDirection.leftToRight)) &&
122+
showSkipButton)
123+
? new SkipButton(
124+
onTap: onPressedSkipButton,
125+
pageButtonViewModel: new PageButtonViewModel(
126+
//View Model
127+
activePageIndex: acitvePageIndex,
128+
totalPages: totalPages,
129+
slidePercent: slidePercent,
130+
slideDirection: slideDirection,
131+
),
132+
)
133+
: new Container(), //Row
134+
), //Padding
135+
136+
new Padding(
137+
padding: const EdgeInsets.only(bottom: 10.0),
138+
child: (acitvePageIndex == totalPages - 1 ||
139+
(acitvePageIndex == totalPages - 2 &&
140+
slideDirection == SlideDirection.rightToLeft))
141+
? new DoneButton(
142+
onTap: onPressedDoneButton,
143+
pageButtonViewModel: new PageButtonViewModel(
144+
//view Model
145+
activePageIndex: acitvePageIndex,
146+
totalPages: totalPages,
147+
slidePercent: slidePercent,
148+
slideDirection: slideDirection,
149+
),
150+
)
151+
: new Container(), //Row
152+
),
153+
],
154+
),
155+
);
190156
}
191157
}

lib/intro_views_flutter.dart

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,45 @@ import 'package:intro_views_flutter/UI/page.dart';
1616

1717
/// This is the IntroViewsFlutter widget of app which is a stateful widget as its state is dynamic and updates asynchronously.
1818
class IntroViewsFlutter extends StatefulWidget {
19+
/// List of [PageViewModel] to display
1920
final List<PageViewModel> pages;
21+
22+
/// Callback on Done Button Pressed
2023
final VoidCallback onTapDoneButton;
24+
25+
/// set the Text Color for skip, done buttons
26+
///
27+
/// gets overiden by [pageButtonTextStyles]
2128
final Color pageButtonsColor;
2229

2330
/// Whether you want to show the skip button or not.
2431
final bool showSkipButton;
25-
final double pageButtonTextSize;
26-
final String pageButtonFontFamily;
32+
33+
/// TextStyles for done, skip Buttons
34+
///
35+
/// overrides [pageButtonFontFamily] [pageButtonsColor] [pageButtonTextSize]
36+
final TextStyle pageButtonTextStyles;
2737

2838
/// run a function after skip Button pressed
2939
final VoidCallback onTapSkipButton;
30-
IntroViewsFlutter(
31-
this.pages, {
32-
this.onTapDoneButton,
33-
this.pageButtonsColor = const Color(0x88FFFFF),
34-
this.showSkipButton = true,
35-
this.pageButtonTextSize = 18.0,
36-
this.pageButtonFontFamily,
37-
this.onTapSkipButton,
38-
});
40+
41+
/// set the Text Size for skip, done buttons
42+
///
43+
/// gets overridden by [pageButtonTextStyles]
44+
final double pageButtonTextSize;
45+
46+
/// set the Font Family for skip, done buttons
47+
///
48+
/// gets overridden by [pageButtonTextStyles]
49+
final String pageButtonFontFamily;
50+
IntroViewsFlutter(this.pages,
51+
{this.onTapDoneButton,
52+
this.showSkipButton = true,
53+
this.pageButtonTextStyles,
54+
this.pageButtonTextSize = 18.0,
55+
this.pageButtonFontFamily,
56+
this.onTapSkipButton,
57+
this.pageButtonsColor});
3958

4059
@override
4160
_IntroViewsFlutterState createState() => new _IntroViewsFlutterState();
@@ -131,6 +150,12 @@ class _IntroViewsFlutterState extends State<IntroViewsFlutter>
131150
132151
@override
133152
Widget build(BuildContext context) {
153+
TextStyle defaultTextStyle = new TextStyle(
154+
fontSize: widget.pageButtonTextSize ?? 18.0,
155+
color: widget.pageButtonsColor ?? const Color(0x88FFFFFF),
156+
fontFamily: widget.pageButtonFontFamily)
157+
.merge(widget.pageButtonTextStyles);
158+
134159
List<PageViewModel> pages = widget.pages;
135160

136161
return new Scaffold(
@@ -159,29 +184,30 @@ class _IntroViewsFlutterState extends State<IntroViewsFlutter>
159184
slidePercent,
160185
),
161186
), //PagerIndicator
162-
new PageIndicatorButtons(
163-
//Skip and Done Buttons
164-
acitvePageIndex: activePageIndex,
165-
totalPages: pages.length,
166-
onPressedDoneButton: widget
167-
.onTapDoneButton, //void Callback to be executed after pressing done button
168-
slidePercent: slidePercent,
169-
slideDirection: slideDirection,
170-
onPressedSkipButton: () {
171-
//method executed on pressing skip button
172-
setState(() {
173-
activePageIndex = pages.length - 1;
174-
nextPageIndex = activePageIndex;
175-
// after skip pressed invoke function
176-
// this can be used for analytics/page transition
177-
if (widget.onTapSkipButton != null) {
178-
widget.onTapSkipButton();
179-
}
180-
});
181-
},
182-
pageButtonsColor: widget.pageButtonsColor,
183-
showSkipButton: widget.showSkipButton,
184-
fontFamily: widget.pageButtonFontFamily,
187+
DefaultTextStyle.merge(
188+
style: defaultTextStyle,
189+
child: PageIndicatorButtons(
190+
//Skip and Done Buttons
191+
acitvePageIndex: activePageIndex,
192+
totalPages: pages.length,
193+
onPressedDoneButton: widget
194+
.onTapDoneButton, //void Callback to be executed after pressing done button
195+
slidePercent: slidePercent,
196+
slideDirection: slideDirection,
197+
onPressedSkipButton: () {
198+
//method executed on pressing skip button
199+
setState(() {
200+
activePageIndex = pages.length - 1;
201+
nextPageIndex = activePageIndex;
202+
// after skip pressed invoke function
203+
// this can be used for analytics/page transition
204+
if (widget.onTapSkipButton != null) {
205+
widget.onTapSkipButton();
206+
}
207+
});
208+
},
209+
showSkipButton: widget.showSkipButton,
210+
),
185211
),
186212
new PageDragger(
187213
//Used for gesture control

0 commit comments

Comments
 (0)