|
1 | 1 | import 'package:flutter/material.dart';
|
2 |
| -import 'package:flutter/services.dart'; |
3 |
| -import 'package:page_view_indicators/circle_page_indicator.dart'; |
| 2 | +import 'package:smooth_page_indicator/smooth_page_indicator.dart'; |
4 | 3 |
|
5 | 4 | const COLOR_ACCENT = 0xFFd756ff;
|
6 | 5 | const COLOR_PRIMARY_DARK = 0xFF6900be;
|
7 | 6 | const COLOR_PRIMARY = 0xFFa011f2;
|
8 | 7 |
|
9 |
| -final _currentPageNotifier = ValueNotifier<int>(0); |
10 | 8 | final List<String> _titlesList = [
|
11 |
| - 'Flutter Onboarding', |
| 9 | + 'Flutter OnBoarding', |
12 | 10 | 'Firebase Auth',
|
13 |
| - 'Facebook Login' |
| 11 | + 'Facebook Login', |
| 12 | + 'Instaflutter.com', |
| 13 | + 'Jump straight into the action.' |
14 | 14 | ];
|
15 | 15 | final List<String> _subtitlesList = [
|
16 |
| - 'Build your onboarding flow in seconds.', |
| 16 | + 'Build your onBoarding flow in seconds.', |
17 | 17 | 'Use Firebase for user managements.',
|
18 |
| - 'Leaverage Facebook to log in user easily.' |
| 18 | + 'Leverage Facebook to log in user easily.', |
| 19 | + 'Get more awesome templates', |
| 20 | + 'Get Started' |
19 | 21 | ];
|
20 |
| -final List<IconData> _imageList = [ |
| 22 | +final List<dynamic> _imageList = [ |
21 | 23 | Icons.developer_mode,
|
22 | 24 | Icons.layers,
|
23 |
| - Icons.account_circle |
| 25 | + Icons.account_circle, |
| 26 | + 'assets/images/ic_launcher_round.png', |
| 27 | + Icons.code |
24 | 28 | ];
|
25 |
| -final List<Widget> _pages = []; |
26 |
| - |
27 |
| -List<Widget> populatePages() { |
28 |
| - _pages.clear(); |
29 |
| - _titlesList.asMap().forEach((index, value) => _pages.add(getPage( |
30 |
| - _imageList.elementAt(index), value, _subtitlesList.elementAt(index)))); |
31 |
| - _pages.add(getLastPage()); |
32 |
| - return _pages; |
33 |
| -} |
34 |
| - |
35 |
| -Widget _buildCircleIndicator() { |
36 |
| - return CirclePageIndicator( |
37 |
| - selectedDotColor: Colors.white, |
38 |
| - dotColor: Colors.white30, |
39 |
| - itemCount: _pages.length, |
40 |
| - selectedSize: 8, |
41 |
| - size: 6.5, |
42 |
| - currentPageNotifier: _currentPageNotifier, |
43 |
| - ); |
44 |
| -} |
45 |
| - |
46 |
| -Widget getPage(IconData icon, String title, String subTitle) { |
47 |
| - return Center( |
48 |
| - child: Container( |
49 |
| - color: Color(COLOR_PRIMARY), |
50 |
| - child: Center( |
51 |
| - child: Padding( |
52 |
| - padding: const EdgeInsets.only(top: 100.0), |
53 |
| - child: Column( |
54 |
| - crossAxisAlignment: CrossAxisAlignment.center, |
55 |
| - children: <Widget>[ |
56 |
| - Padding( |
57 |
| - padding: const EdgeInsets.all(40.0), |
58 |
| - child: new Icon( |
59 |
| - icon, |
60 |
| - color: Colors.white, |
61 |
| - size: 120, |
62 |
| - ), |
63 |
| - ), |
64 |
| - Text( |
65 |
| - title, |
66 |
| - style: TextStyle( |
67 |
| - color: Colors.white, |
68 |
| - fontSize: 20.0, |
69 |
| - fontWeight: FontWeight.bold), |
70 |
| - ), |
71 |
| - Padding( |
72 |
| - padding: const EdgeInsets.all(16.0), |
73 |
| - child: Text( |
74 |
| - subTitle, |
75 |
| - style: TextStyle(color: Colors.white70, fontSize: 17.0), |
76 |
| - ), |
77 |
| - ) |
78 |
| - ], |
79 |
| - ), |
80 |
| - ), |
81 |
| - ), |
82 |
| - ), |
83 |
| - ); |
84 |
| -} |
85 |
| - |
86 |
| -Widget getLastPage() { |
87 |
| - return Center( |
88 |
| - child: Container( |
89 |
| - color: Color(COLOR_PRIMARY), |
90 |
| - child: Center( |
91 |
| - child: Padding( |
92 |
| - padding: const EdgeInsets.only(bottom: 40.0), |
93 |
| - child: Column( |
94 |
| - mainAxisAlignment: MainAxisAlignment.center, |
95 |
| - crossAxisAlignment: CrossAxisAlignment.center, |
96 |
| - children: <Widget>[ |
97 |
| - Padding( |
98 |
| - padding: const EdgeInsets.all(40.0), |
99 |
| - child: new Icon( |
100 |
| - Icons.code, |
101 |
| - color: Colors.white, |
102 |
| - size: 120, |
103 |
| - ), |
104 |
| - ), |
105 |
| - Text( |
106 |
| - 'Jump straight into the action.', |
107 |
| - style: TextStyle( |
108 |
| - color: Colors.white, |
109 |
| - fontSize: 20.0, |
110 |
| - fontWeight: FontWeight.bold), |
111 |
| - ), |
112 |
| - Padding( |
113 |
| - padding: const EdgeInsets.all(16.0), |
114 |
| - child: OutlineButton( |
115 |
| - onPressed: () {}, |
116 |
| - child: Text( |
117 |
| - "Get Started", |
118 |
| - style: TextStyle( |
119 |
| - fontSize: 20.0, |
120 |
| - color: Colors.white, |
121 |
| - fontWeight: FontWeight.bold), |
122 |
| - ), |
123 |
| - borderSide: BorderSide(color: Colors.white), |
124 |
| - shape: StadiumBorder(), |
125 |
| - )) |
126 |
| - ], |
127 |
| - ), |
128 |
| - ), |
129 |
| - ), |
130 |
| - ), |
131 |
| - ); |
132 |
| -} |
133 | 29 |
|
134 | 30 | class MyApp extends StatefulWidget {
|
135 | 31 | @override
|
136 | 32 | _MyAppState createState() => _MyAppState();
|
137 | 33 | }
|
138 | 34 |
|
139 | 35 | class _MyAppState extends State<MyApp> {
|
| 36 | + int _currentIndex = 0; |
| 37 | + PageController pageController = PageController(); |
| 38 | + |
140 | 39 | @override
|
141 | 40 | Widget build(BuildContext context) {
|
142 |
| - SystemChrome.setSystemUIOverlayStyle( |
143 |
| - SystemUiOverlayStyle(statusBarColor: Color(COLOR_PRIMARY_DARK))); |
144 | 41 | return MaterialApp(
|
145 | 42 | debugShowCheckedModeBanner: false,
|
146 | 43 | home: Scaffold(
|
147 |
| - body: Stack( |
148 |
| - children: <Widget>[ |
149 |
| - PageView( |
150 |
| - children: populatePages(), |
151 |
| - onPageChanged: (int index) { |
152 |
| - _currentPageNotifier.value = index; |
153 |
| - }, |
154 |
| - ), |
155 |
| - Padding( |
156 |
| - padding: const EdgeInsets.only(bottom: 30.0), |
157 |
| - child: Align( |
158 |
| - alignment: Alignment.bottomCenter, |
159 |
| - child: _buildCircleIndicator(), |
| 44 | + backgroundColor: Color(COLOR_PRIMARY), |
| 45 | + body: Stack( |
| 46 | + children: <Widget>[ |
| 47 | + PageView.builder( |
| 48 | + itemBuilder: (context, index) => getPage( |
| 49 | + _imageList[index], |
| 50 | + _titlesList[index], |
| 51 | + _subtitlesList[index], |
| 52 | + context, |
| 53 | + index + 1 == _titlesList.length), |
| 54 | + controller: pageController, |
| 55 | + itemCount: _titlesList.length, |
| 56 | + onPageChanged: (int index) { |
| 57 | + setState(() { |
| 58 | + _currentIndex = index; |
| 59 | + }); |
| 60 | + }, |
160 | 61 | ),
|
161 |
| - ) |
162 |
| - ], |
163 |
| - )), |
| 62 | + Padding( |
| 63 | + padding: const EdgeInsets.only(bottom: 50.0), |
| 64 | + child: Align( |
| 65 | + alignment: Alignment.bottomCenter, |
| 66 | + child: SmoothPageIndicator( |
| 67 | + controller: pageController, |
| 68 | + count: _titlesList.length, |
| 69 | + effect: ScrollingDotsEffect( |
| 70 | + activeDotColor: Colors.white, |
| 71 | + dotColor: Colors.grey.shade400, |
| 72 | + dotWidth: 8, |
| 73 | + dotHeight: 8), |
| 74 | + ), |
| 75 | + ), |
| 76 | + ) |
| 77 | + ], |
| 78 | + ), |
| 79 | + ), |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + Widget getPage(dynamic image, String title, String subTitle, |
| 84 | + BuildContext context, bool isLastPage) { |
| 85 | + return Column( |
| 86 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 87 | + mainAxisAlignment: MainAxisAlignment.center, |
| 88 | + children: <Widget>[ |
| 89 | + image is String |
| 90 | + ? Image.asset( |
| 91 | + image, |
| 92 | + width: 150, |
| 93 | + height: 150, |
| 94 | + fit: BoxFit.cover, |
| 95 | + ) |
| 96 | + : Icon( |
| 97 | + image as IconData, |
| 98 | + color: Colors.white, |
| 99 | + size: 150, |
| 100 | + ), |
| 101 | + SizedBox(height: 40), |
| 102 | + Text( |
| 103 | + title.toUpperCase(), |
| 104 | + style: TextStyle( |
| 105 | + color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold), |
| 106 | + textAlign: TextAlign.center, |
| 107 | + ), |
| 108 | + Padding( |
| 109 | + padding: const EdgeInsets.all(16.0), |
| 110 | + child: _currentIndex + 1 == _titlesList.length |
| 111 | + ? OutlineButton( |
| 112 | + onPressed: () {}, |
| 113 | + child: Text( |
| 114 | + "Get Started", |
| 115 | + style: TextStyle( |
| 116 | + fontSize: 20.0, |
| 117 | + color: Colors.white, |
| 118 | + fontWeight: FontWeight.bold), |
| 119 | + ), |
| 120 | + borderSide: BorderSide(color: Colors.white), |
| 121 | + shape: StadiumBorder(), |
| 122 | + ) |
| 123 | + : Text( |
| 124 | + subTitle, |
| 125 | + style: TextStyle(color: Colors.white, fontSize: 14.0), |
| 126 | + textAlign: TextAlign.center, |
| 127 | + ), |
| 128 | + ), |
| 129 | + ], |
164 | 130 | );
|
165 | 131 | }
|
166 | 132 | }
|
|
0 commit comments