Advertisement
zidniryi

onboarding_screen.dart

Jun 27th, 2020
1,433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.15 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:news_flutter/utilities/styles.dart';
  4.  
  5. class OnboardingScreen extends StatefulWidget {
  6. @override
  7. _OnboardingScreenState createState() => _OnboardingScreenState();
  8. }
  9.  
  10. class _OnboardingScreenState extends State<OnboardingScreen> {
  11. final int _numPages = 3;
  12. final PageController _pageController = PageController(initialPage: 0);
  13. int _currentPage = 0;
  14.  
  15. List<Widget> _buildPageIndicator() {
  16. List<Widget> list = [];
  17. for (int i = 0; i < _numPages; i++) {
  18. list.add(i == _currentPage ? _indicator(true) : _indicator(false));
  19. }
  20. return list;
  21. }
  22.  
  23. Widget _indicator(bool isActive) {
  24. return AnimatedContainer(
  25. duration: Duration(milliseconds: 150),
  26. margin: EdgeInsets.symmetric(horizontal: 8.0),
  27. height: 8.0,
  28. width: isActive ? 24.0 : 16.0,
  29. decoration: BoxDecoration(
  30. color: isActive ? Colors.white : Color(0xFF7B51D3),
  31. borderRadius: BorderRadius.all(Radius.circular(12)),
  32. ),
  33. );
  34. }
  35.  
  36. @override
  37. Widget build(BuildContext context) {
  38. return Scaffold(
  39. resizeToAvoidBottomPadding: false ,
  40. body: AnnotatedRegion<SystemUiOverlayStyle>(
  41. value: SystemUiOverlayStyle.light,
  42. child: Container(
  43. decoration: BoxDecoration(
  44. gradient: LinearGradient(
  45. begin: Alignment.topCenter,
  46. stops: [0.1, 0.4, 0.7, 0.9],
  47. colors: [
  48. Color(4278249078),
  49. Color(4278241363),
  50. Color(4278249078),
  51. Color(4278241363),
  52. ],
  53. ),
  54. ),
  55. child:
  56. Padding(
  57. padding: EdgeInsets.symmetric(vertical: 20.0),
  58. child: Column(
  59. crossAxisAlignment: CrossAxisAlignment.stretch,
  60. children: <Widget>[
  61. _currentPage != _numPages - 1
  62. ? Container(
  63. alignment: Alignment.centerRight,
  64. child: FlatButton(
  65. onPressed: () {
  66. _pageController.nextPage(
  67. duration: Duration(milliseconds: 500),
  68. curve: Curves.ease,
  69. );
  70. },
  71. child: Text(
  72. 'Next',
  73. style: TextStyle(
  74. color: Colors.white,
  75. fontSize: 20.0,
  76. ),
  77. ),
  78. ),
  79. ) : Text(""),
  80. Container(
  81. height: 600.0,
  82. child: PageView(
  83. physics: ClampingScrollPhysics(),
  84. controller: _pageController,
  85. onPageChanged: (int page) {
  86. setState(() {
  87. _currentPage = page;
  88. });
  89. },
  90. children: <Widget>[
  91. Padding(
  92. padding: EdgeInsets.all(20.0),
  93. child: Column(
  94. crossAxisAlignment: CrossAxisAlignment.start,
  95. children: <Widget>[
  96. Center(
  97. child: Image(
  98. image: AssetImage(
  99. 'assets/images/onboarding0.png',
  100. ),
  101. height: 200.0,
  102. width: 200.0,
  103. ),
  104. ),
  105. SizedBox(height: 50.0),
  106. Text(
  107. 'Connect human\naround the world',
  108. style: kTitleStyle,
  109. ),
  110. SizedBox(height: 15.0),
  111. Text(
  112. 'Lorem ipsum dolor sit amet, consect adipiscing elit, sed do eiusmod tempor incididunt ut labore et.',
  113. style: kSubtitleStyle,
  114. ),
  115. ],
  116. ),
  117. ),
  118. Padding(
  119. padding: EdgeInsets.all(40.0),
  120. child: Column(
  121. crossAxisAlignment: CrossAxisAlignment.start,
  122. children: <Widget>[
  123. Center(
  124. child: Image(
  125. image: AssetImage(
  126. 'assets/images/onboarding1.png',
  127. ),
  128. height: 200.0,
  129. width: 200.0,
  130. ),
  131. ),
  132. SizedBox(height: 50.0),
  133. Text(
  134. 'Live your life smarter\nwith us!',
  135. style: kTitleStyle,
  136. ),
  137. SizedBox(height: 15.0),
  138. Text(
  139. 'Lorem ipsum dolor sit amet, consect adipiscing elit, sed do eiusmod tempor incididunt ut labore et.',
  140. style: kSubtitleStyle,
  141. ),
  142. ],
  143. ),
  144. ),
  145. Padding(
  146. padding: EdgeInsets.all(40.0),
  147. child: Column(
  148. crossAxisAlignment: CrossAxisAlignment.start,
  149. children: <Widget>[
  150. Center(
  151. child: Image(
  152. image: AssetImage(
  153. 'assets/images/onboarding2.png',
  154. ),
  155. height: 200.0,
  156. width: 200.0,
  157. ),
  158. ),
  159. SizedBox(height: 50.0),
  160. Text(
  161. 'Get a new experience\nof imagination',
  162. style: kTitleStyle,
  163. ),
  164. SizedBox(height: 15.0),
  165. Text(
  166. 'Lorem ipsum dolor sit amet, consect adipiscing elit, sed do eiusmod tempor incididunt ut labore et.',
  167. style: kSubtitleStyle,
  168. ),
  169. ],
  170. ),
  171. ),
  172. ],
  173. ),
  174. ),
  175. Row(
  176. mainAxisAlignment: MainAxisAlignment.center,
  177. children: _buildPageIndicator(),
  178. ),
  179. _currentPage != _numPages - 1
  180. ? Expanded(
  181. child: Align(
  182. alignment: FractionalOffset.bottomRight,
  183. child: FlatButton(
  184. onPressed: () {
  185. _pageController.nextPage(
  186. duration: Duration(milliseconds: 500),
  187. curve: Curves.ease,
  188. );
  189. },
  190. child: Row(
  191. mainAxisAlignment: MainAxisAlignment.center,
  192. mainAxisSize: MainAxisSize.min,
  193. children: <Widget>[
  194. Text(
  195. 'Next',
  196. style: TextStyle(
  197. color: Colors.white,
  198. fontSize: 22.0,
  199. ),
  200. ),
  201. SizedBox(width: 10.0),
  202. Icon(
  203. Icons.arrow_forward,
  204. color: Colors.white,
  205. size: 50.0,
  206. ),
  207. ],
  208. ),
  209. ),
  210. ),
  211. )
  212. : Text(''),
  213. ],
  214. ),
  215. ),
  216. ),
  217. ),
  218. bottomSheet: _currentPage == _numPages - 1
  219. ? Container(
  220. height: 100.0,
  221. width: double.infinity,
  222. color: Colors.white,
  223. child: GestureDetector(
  224. onTap: () => print('Get started'),
  225. child: Center(
  226. child: Padding(
  227. padding: EdgeInsets.only(bottom: 10.0),
  228. child: Text(
  229. 'Get started',
  230. style: TextStyle(
  231. color: Color(4278241363),
  232. fontSize: 20.0,
  233. fontWeight: FontWeight.bold,
  234. ),
  235. ),
  236. ),
  237. ),
  238. ),
  239. )
  240. : Container(
  241. height: 100.0,
  242. width: double.infinity,
  243. decoration: BoxDecoration(
  244. gradient: LinearGradient(
  245. stops: [0.1, 0.4, 0.7, 0.9],
  246. colors: [
  247. Color(4278241363),
  248. Color(4278241363),
  249. Color(4278241363),
  250. Color(4278241363),
  251. ],
  252. ),
  253. ),
  254.  
  255. child: GestureDetector(
  256.  
  257. onTap: () => print('Get started'),
  258. child: Center(
  259. child: Padding(
  260.  
  261. padding: EdgeInsets.only(bottom: 10.0),
  262.  
  263. ),
  264. ),
  265. ),
  266. )
  267. ,
  268. );
  269. }
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement