Advertisement
Guest User

FULL CODE CAROUSEL

a guest
Dec 29th, 2018
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.18 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/animation.dart';
  3.  
  4. class Intro extends StatefulWidget {
  5. @override
  6. _IntroState createState() => _IntroState();
  7. }
  8.  
  9. class _IntroState extends State<Intro> with TickerProviderStateMixin {
  10. Animation animation, fadeout;
  11. AnimationController animationController, fadeController;
  12. PageController controller;
  13.  
  14. int carouselIndex, itemIndex;
  15.  
  16. @override
  17. void initState() {
  18. super.initState();
  19. controller = PageController(
  20. initialPage: 0,
  21. keepPage: true,
  22. viewportFraction: 0.8,
  23. );
  24.  
  25. animationController = AnimationController(
  26. duration: Duration(seconds: 2),
  27. vsync: this,
  28. );
  29. fadeController = AnimationController(
  30. duration: Duration(seconds: 7),
  31. vsync: this,
  32. );
  33.  
  34. fadeout = Tween(begin: -1.0, end: 0.0)
  35. .animate(CurvedAnimation(parent: fadeController, curve: Curves.easeIn));
  36. fadeController.forward();
  37.  
  38. animation = Tween(begin: -1.0, end: 0.0).animate(CurvedAnimation(
  39. parent: animationController, curve: Curves.fastOutSlowIn));
  40. animationController.forward();
  41. }
  42.  
  43. @override
  44. Widget build(BuildContext context) {
  45. final double width = MediaQuery.of(context).size.width;
  46.  
  47. return AnimatedBuilder(
  48. animation: animationController,
  49. builder: (BuildContext context, Widget child) {
  50. return Scaffold(
  51. appBar: new AppBar(
  52. backgroundColor: Colors.white,
  53. elevation: 2.0,
  54. leading: IconButton(
  55. icon: Icon(
  56. Icons.list,
  57. color: Colors.red,
  58. ),
  59. onPressed: () {
  60. Navigator.pop(context);
  61. }),
  62. ),
  63. body: ListView(children: <Widget>[
  64. new Stack(
  65. children: <Widget>[
  66. new AspectRatio(
  67. aspectRatio: 10 / 100,
  68. child: new Container(
  69. decoration: BoxDecoration(
  70. image: DecorationImage(
  71. image: AssetImage('assets/dashboard.png'),
  72. alignment: Alignment.topCenter)),
  73. ),
  74. ),
  75. new Transform(
  76. transform: Matrix4.translationValues(
  77. animation.value * width,
  78. 0.0,
  79. 0.0,
  80. ),
  81. child: Padding(
  82. padding: const EdgeInsets.symmetric(horizontal: 12.0),
  83. child: Container(
  84. child: Column(
  85. children: <Widget>[
  86. SizedBox(height: 60.0),
  87. new Row(
  88. children: <Widget>[
  89. Expanded(
  90. child: Column(
  91. mainAxisAlignment: MainAxisAlignment.start,
  92. crossAxisAlignment:
  93. CrossAxisAlignment.start,
  94. children: <Widget>[
  95. Text(
  96. 'Have you',
  97. style: TextStyle(
  98. color: Colors.black,
  99. fontSize: 24.0,
  100. height: 0.1),
  101. ),
  102. Padding(
  103. padding:
  104. const EdgeInsets.only(left: 8.0),
  105. child: Text(
  106. 'subscribe',
  107. style: TextStyle(
  108. color: Color(0xFFFFB300),
  109. fontSize: 24.0,
  110. height: 0.9),
  111. ),
  112. ),
  113. Padding(
  114. padding:
  115. const EdgeInsets.only(left: 13.0),
  116. child: Text(
  117. 'PewDiePie?',
  118. style: TextStyle(
  119. color: Color(0xFFFF1744),
  120. fontSize: 24.0,
  121. height: 0.8),
  122. ),
  123. )
  124. ],
  125. )),
  126. ],
  127. ),
  128. SizedBox(height: 7.7),
  129. ],
  130. ),
  131. ),
  132. ),
  133. ),
  134. new FadeTransition(
  135. opacity: fadeController
  136. .drive(CurveTween(curve: Curves.easeIn)),
  137. child: new Padding(
  138. padding: const EdgeInsets.symmetric(
  139. horizontal: 22.0, vertical: 115.0),
  140. child: new Row(
  141. children: <Widget>[
  142. Expanded(
  143. child: Row(
  144. children: <Widget>[
  145. new Padding(
  146. padding: const EdgeInsets.only(right: 3.3),
  147. child: new Container(
  148. height: 40.0,
  149. width: 65.0,
  150. decoration: BoxDecoration(
  151. color: Colors.red,
  152. borderRadius:
  153. BorderRadius.circular(5.0),
  154. ),
  155. child: Column(
  156. mainAxisAlignment:
  157. MainAxisAlignment.center,
  158. children: <Widget>[
  159. Text('yes',
  160. style: TextStyle(
  161. color: Colors.white,
  162. fontSize: 21.5))
  163. ],
  164. ),
  165. ),
  166. ),
  167. new Padding(
  168. padding: const EdgeInsets.only(left: 3.3),
  169. child: new Container(
  170. height: 40.0,
  171. width: 65.0,
  172. decoration: BoxDecoration(
  173. color: Colors.greenAccent,
  174. borderRadius:
  175. BorderRadius.circular(5.0),
  176. ),
  177. child: Column(
  178. mainAxisAlignment:
  179. MainAxisAlignment.center,
  180. children: <Widget>[
  181. Text('no',
  182. style: TextStyle(
  183. color: Colors.white,
  184. fontSize: 21.5))
  185. ],
  186. ),
  187. ),
  188. )
  189. ],
  190. ),
  191. )
  192. ],
  193. ),
  194. ),
  195. ),
  196. //HORIZONTAL LISTVIEW
  197. new ListView.builder(
  198. itemCount: 3,
  199. scrollDirection: Axis.horizontal,
  200. padding: EdgeInsets.symmetric(vertical: 16.0),
  201. itemBuilder: (BuildContext context, int index) {
  202. if (index % 3 == 0) {
  203. return _buildCarousel(context, index ~/ 3);
  204. } else {
  205. return Divider();
  206. }
  207. },
  208. ),
  209. ],
  210. ),
  211. ]));
  212. });
  213. }
  214.  
  215. Widget _buildCarousel(BuildContext context, int carouselIndex) {
  216. return Column(
  217. mainAxisSize: MainAxisSize.min,
  218. children: <Widget>[
  219. Text('Carousel $carouselIndex'),
  220. SizedBox(
  221. // you may want to use an aspect ratio here for tablet support
  222. height: 200.0,
  223. child: PageView.builder(
  224. // store this controller in a State to save the carousel scroll position
  225. controller: PageController(viewportFraction: 0.8),
  226. itemBuilder: (BuildContext context, int itemIndex) {
  227. return _buildCarouselItem(context, carouselIndex, itemIndex);
  228. },
  229. ),
  230. )
  231. ],
  232. );
  233. }
  234.  
  235. Widget _buildCarouselItem(
  236. BuildContext context, int carouselIndex, int itemIndex) {
  237. return Padding(
  238. padding: EdgeInsets.symmetric(horizontal: 4.0),
  239. child: Container(
  240. decoration: BoxDecoration(
  241. color: Colors.grey,
  242. borderRadius: BorderRadius.all(Radius.circular(4.0)),
  243. ),
  244. ),
  245. );
  246. }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement