1
+ import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_swiper/flutter_swiper.dart' ;
3
+ import 'package:flutter_ui_challenges/core/presentation/res/assets.dart' ;
4
+ import 'package:flutter_ui_challenges/src/widgets/swiper_pagination.dart' ;
5
+ import 'package:cached_network_image/cached_network_image.dart' ;
6
+ import 'package:font_awesome_flutter/font_awesome_flutter.dart' ;
7
+
8
+ class IntroThreePage extends StatefulWidget {
9
+ static final String path = "lib/src/pages/onboarding/intro3.dart" ;
10
+ @override
11
+ _IntroThreePageState createState () => _IntroThreePageState ();
12
+ }
13
+
14
+ class _IntroThreePageState extends State <IntroThreePage > {
15
+ final SwiperController _swiperController = SwiperController ();
16
+ final int _pageCount = 3 ;
17
+ int _currentIndex = 0 ;
18
+ final List <String > titles = [
19
+ "Lorem ipsum dolor \n sit amet, consectetur adipiscing \n elit placerat. " ,
20
+ "Aliquam eget justo \n nec arcu ultricies elementum \n id at metus. " ,
21
+ "Nulla facilisi. \n Fusce non tempus risus.\n Sed ultrices scelerisque sem,"
22
+ ];
23
+ final List <Color > pageBgs = [
24
+ Colors .blue.shade300,
25
+ Colors .grey.shade600,
26
+ Colors .cyan.shade300
27
+ ];
28
+
29
+ @override
30
+ Widget build (BuildContext context){
31
+ return Scaffold (
32
+ backgroundColor: Colors .white,
33
+ body: Stack (
34
+ children: < Widget > [
35
+ Center (child: Container (
36
+ height: 300 ,
37
+ margin: const EdgeInsets .only (left: 8.0 , right: 8.0 ),
38
+ decoration: BoxDecoration (
39
+ color: Theme .of (context).accentColor,
40
+ borderRadius: BorderRadius .circular (5.0 )
41
+ ),
42
+ ),),
43
+ Column (
44
+ mainAxisAlignment: MainAxisAlignment .center,
45
+ children: < Widget > [
46
+ Expanded (child: Swiper (
47
+ index: _currentIndex,
48
+ controller: _swiperController,
49
+ itemCount: _pageCount,
50
+ onIndexChanged: (index) {
51
+ setState (() {
52
+ _currentIndex = index;
53
+ });
54
+ },
55
+ loop: false ,
56
+ itemBuilder: (context, index){
57
+ return _buildPage (title: titles[index], icon: images[index+ 2 ], pageBg: pageBgs[index]);
58
+ },
59
+ pagination: SwiperPagination (
60
+ builder: CustomPaginationBuilder (
61
+ activeSize: Size (10.0 , 20.0 ),
62
+ size: Size (10.0 , 15.0 ),
63
+ color: Colors .grey.shade600
64
+ )
65
+ ),
66
+ )),
67
+ SizedBox (height: 10.0 ),
68
+ _buildButtons (),
69
+ ],
70
+ ),
71
+ ],
72
+ ),
73
+ );
74
+ }
75
+
76
+ Widget _buildButtons (){
77
+ return Container (
78
+ margin: const EdgeInsets .only (right: 16.0 ),
79
+ child: Row (
80
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
81
+ children: < Widget > [
82
+ FlatButton (
83
+ textColor: Colors .grey.shade600,
84
+ child: Text ("Skip" ),
85
+ onPressed: (){
86
+ Navigator .of (context).pushReplacementNamed ('home' );
87
+ },
88
+ ),
89
+ IconButton (
90
+ icon: Icon (_currentIndex < _pageCount - 1 ? Icons .arrow_forward_ios : FontAwesomeIcons .check),
91
+ onPressed: () async {
92
+ if (_currentIndex < _pageCount - 1 )
93
+ _swiperController.next ();
94
+ else {
95
+ Navigator .of (context).pushReplacementNamed ('home' );
96
+ }
97
+ },
98
+ )
99
+ ],
100
+ ),
101
+ );
102
+ }
103
+
104
+ Widget _buildPage ({String title, String icon, Color pageBg}) {
105
+ final TextStyle titleStyle = TextStyle (
106
+ fontWeight: FontWeight .w500,
107
+ fontSize: 20.0 ,
108
+ color: Colors .white
109
+ );
110
+ return Container (
111
+ width: double .infinity,
112
+ margin: const EdgeInsets .fromLTRB (16.0 , 50.0 ,16.0 ,40.0 ),
113
+ padding: const EdgeInsets .all (16.0 ),
114
+ decoration: BoxDecoration (
115
+ borderRadius: BorderRadius .circular (30.0 ),
116
+ color: pageBg
117
+ ),
118
+ child: Column (
119
+ mainAxisAlignment: MainAxisAlignment .center,
120
+ children: < Widget > [
121
+ SizedBox (height: 20.0 ),
122
+ Text (title, textAlign: TextAlign .center, style: titleStyle,),
123
+ SizedBox (height: 30.0 ),
124
+ Expanded (
125
+ child: ClipOval (child: Container (
126
+ height: 300 ,
127
+ width: 300 ,
128
+ decoration: BoxDecoration (
129
+ image: DecorationImage (
130
+ image: CachedNetworkImageProvider (icon),
131
+ fit: BoxFit .cover
132
+ )
133
+ ),
134
+ )) ,
135
+ ),
136
+
137
+ SizedBox (height: 50.0 ),
138
+ ],
139
+ ),
140
+ );
141
+ }
142
+ }
0 commit comments