[무작정 플러터 강의노트] 06 홈 화면에 원형 이미지 / 사각형 이미지 슬라이더 위젯 추가하기

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// detail_screen.dart
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/model/model_movie.dart';

class DetailScreen extends StatefulWidget {
final Movie movie;
DetailScreen({this.movie});
_DetailScreenState createState() => _DetailScreenState();
}

class _DetailScreenState extends State<DetailScreen> {
bool like = false;
@override
void initState() {
super.initState();
like = widget.movie.like;
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: SafeArea(
child: ListView(
children: <Widget>[
Stack(
children: <Widget>[
Container(
width: double.maxFinite,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/' + widget.movie.poster),
fit: BoxFit.cover,
),
),
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container(
alignment: Alignment.center,
color: Colors.black.withOpacity(0.1),
child: Container(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(0, 45, 0, 10),
child: Image.asset(
'images/' + widget.movie.poster),
height: 300,
),
Container(
padding: EdgeInsets.all(7),
child: Text(
'99% 일치 2019 15+ 시즌 1개',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 13),
),
),
Container(
padding: EdgeInsets.all(7),
child: Text(
widget.movie.title,
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16),
),
),
Container(
padding: EdgeInsets.all(3),
child: FlatButton(
onPressed: () {},
color: Colors.red,
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.play_arrow),
Text('재생'),
],
),
),
),
Container(
padding: EdgeInsets.all(5),
child: Text(widget.movie.toString()),
),
Container(
padding: EdgeInsets.all(5),
alignment: Alignment.centerLeft,
child: Text(
'출연: 현빈, 손예진, 서지혜\n제작자: 이정효, 박지은',
style: TextStyle(
color: Colors.white60,
fontSize: 12,
),
),
)
],
),
),
),
),
),
),
Positioned(
child: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
),
),
],
),
Container(
color: Colors.black26,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
child: InkWell(
onTap: () {},
child: Column(
children: <Widget>[
like ? Icon(Icons.check) : Icon(Icons.add),
Padding(
padding: EdgeInsets.all(5),
),
Text(
'내가 찜한 콘텐츠',
style: TextStyle(
fontSize: 11,
color: Colors.white60,
),
)
],
),
),
),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
child: Container(
child: Column(
children: <Widget>[
Icon(Icons.thumb_up),
Padding(
padding: EdgeInsets.all(5),
),
Text(
'평가',
style: TextStyle(
fontSize: 11, color: Colors.white60),
)
],
),
),
),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
child: Container(
child: Column(
children: <Widget>[
Icon(Icons.send),
Padding(padding: EdgeInsets.all(5)),
Text(
'공유',
style: TextStyle(
fontSize: 11, color: Colors.white60),
),
],
),
),
)
],
),
)
],
),
),
),
);
}
}
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
146
147
148
149
150
151
152
153
154
// carousel_slider.dart
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/model/model_movie.dart';
import 'package:netflix_clone_lecture_note/screen/detail_screen.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('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: () {
Navigator.of(context).push(MaterialPageRoute<Null>(
fullscreenDialog: true,
builder: (BuildContext context) {
return DetailScreen(
movie: movies[_currentPage],
);
}));
},
),
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;
}
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
// circle_slider.dart
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/model/model_movie.dart';
import 'package:netflix_clone_lecture_note/screen/detail_screen.dart';

class CircleSlider extends StatelessWidget {
final List<Movie> movies;
CircleSlider({this.movies});
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(7),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('미리보기'),
Container(
height: 120,
child: ListView(
scrollDirection: Axis.horizontal,
children: makeCircleImages(context, movies),
),
),
],
),
);
}
}

List<Widget> makeCircleImages(BuildContext context, List<Movie> movies) {
List<Widget> results = [];
for (var i = 0; i < movies.length; i++) {
results.add(
InkWell(
onTap: () {
Navigator.of(context).push(MaterialPageRoute<Null>(
fullscreenDialog: true,
builder: (BuildContext context) {
return DetailScreen(
movie: movies[i],
);
}));
},
child: Container(
padding: EdgeInsets.only(right: 10),
child: Align(
alignment: Alignment.centerLeft,
child: CircleAvatar(
backgroundImage: AssetImage('images/' + movies[i].poster),
radius: 48,
),
),
),
),
);
}
return results;
}
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
// box_slider.dart
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/model/model_movie.dart';
import 'package:netflix_clone_lecture_note/screen/detail_screen.dart';

class BoxSlider extends StatelessWidget {
final List<Movie> movies;
BoxSlider({this.movies});
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(7),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('지금 뜨는 콘텐츠'),
Container(
height: 120,
child: ListView(
scrollDirection: Axis.horizontal,
children: makeBoxImages(context, movies),
),
)
],
),
);
}
}

List<Widget> makeBoxImages(BuildContext context, List<Movie> movies) {
List<Widget> results = [];
for (var i = 0; i < movies.length; i++) {
results.add(InkWell(
onTap: () {
Navigator.of(context).push(MaterialPageRoute<Null>(
fullscreenDialog: true,
builder: (BuildContext context) {
return DetailScreen(
movie: movies[i],
);
}));
},
child: Container(
padding: EdgeInsets.only(right: 10),
child: Align(
alignment: Alignment.centerLeft,
child: Image.asset('images/' + movies[i].poster),
),
),
));
}
return results;
}

[무작정 플러터 강의노트] 06 홈 화면에 원형 이미지 / 사각형 이미지 슬라이더 위젯 추가하기

https://taebbong.github.io/2020/03/23/2020-03-23-bbongflix-lec06-post/

Author

TaeBbong Kwon

Posted on

2020-03-23

Updated on

2022-08-06

Licensed under

Comments