1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:netflix_clone_lecture_note/model/model_movie.dart';
class CarouselImage extends StatefulWidget { final List<Movie> movies; CarouselImage({this.movies}); _CarouselImageState createState() => _CarouselImageState(); }
class _CarouselImageState extends State<CarouselImage> { List<Movie> movies; List<Widget> images; List<String> keywords; List<bool> likes; int _currentPage = 0; String _currentKeyword;
@override void initState() { super.initState(); movies = widget.movies; images = movies.map((m) => Image.asset('./img/images/' + m.poster)).toList(); keywords = movies.map((m) => m.keyword).toList(); likes = movies.map((m) => m.like).toList(); _currentKeyword = keywords[0]; }
@override Widget build(BuildContext context) { return Container( child: Column( children: <Widget>[ Container( padding: EdgeInsets.all(20), ), CarouselSlider( items: images, onPageChanged: (index) { setState(() { _currentPage = index; _currentKeyword = keywords[_currentPage]; }); }, ), Container( padding: EdgeInsets.fromLTRB(0, 10, 0, 3), child: Text( _currentKeyword, style: TextStyle(fontSize: 11), ), ), Container( child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ Container( child: Column( children: <Widget>[ likes[_currentPage] ? IconButton( icon: Icon(Icons.check), onPressed: () {}, ) : IconButton( icon: Icon(Icons.add), onPressed: () {}, ), Text( '내가 찜한 콘텐츠', style: TextStyle(fontSize: 11), ) ], ), ), Container( padding: EdgeInsets.only(right: 10), child: FlatButton( color: Colors.white, onPressed: () {}, child: Row( children: <Widget>[ Icon( Icons.play_arrow, color: Colors.black, ), Padding( padding: EdgeInsets.all(3), ), Text( '재생', style: TextStyle(color: Colors.black), ) ], ), ), ), Container( padding: EdgeInsets.only(right: 10), child: Column( children: <Widget>[ IconButton( icon: Icon(Icons.info), onPressed: () {}, ), Text( '정보', style: TextStyle(fontSize: 11), ) ], ), ), ], ), ), Container( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: makeIndicator(likes, _currentPage), ), ) ], ), ); } }
List<Widget> makeIndicator(List list, int _currentPage) { List<Widget> results = []; for (var i = 0; i < list.length; i++) { results.add(Container( width: 8, height: 8, margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 2.0), decoration: BoxDecoration( shape: BoxShape.circle, color: _currentPage == i ? Color.fromRGBO(255, 255, 255, 0.9) : Color.fromRGBO(255, 255, 255, 0.4)), )); }
return results; }
|