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

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
// home_screen.dart
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/model/model_movie.dart';
import 'package:netflix_clone_lecture_note/widget/box_slider.dart';
import 'package:netflix_clone_lecture_note/widget/carousel_slider.dart';
import 'package:netflix_clone_lecture_note/widget/circle_slider.dart';

class HomeScreen extends StatefulWidget {
_HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
List<Movie> movies = [
Movie.fromMap({
'title': '사랑의 불시착',
'keyword': '사랑/로맨스/판타지',
'poster': 'test_movie_1.png',
'like': false
}),
Movie.fromMap({
'title': '사랑의 불시착',
'keyword': '사랑/로맨스/판타지',
'poster': 'test_movie_1.png',
'like': false
}),
Movie.fromMap({
'title': '사랑의 불시착',
'keyword': '사랑/로맨스/판타지',
'poster': 'test_movie_1.png',
'like': false
}),
Movie.fromMap({
'title': '사랑의 불시착',
'keyword': '사랑/로맨스/판타지',
'poster': 'test_movie_1.png',
'like': false
}),
];
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
Stack(
children: <Widget>[
CarouselImage(movies: movies),
TopBar(),
],
),
CircleSlider(movies: movies),
BoxSlider(movies: movies),
],
);
}
}

class TopBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(20, 7, 20, 7),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Image.asset(
'images/bbongflix_logo.png',
fit: BoxFit.contain,
height: 25,
),
Container(
padding: EdgeInsets.only(right: 1),
child: Text(
'TV 프로그램',
style: TextStyle(fontSize: 14),
),
),
Container(
padding: EdgeInsets.only(right: 1),
child: Text(
'영화',
style: TextStyle(fontSize: 14),
),
),
Container(
padding: EdgeInsets.only(right: 1),
child: Text(
'내가 찜한 콘텐츠',
style: TextStyle(fontSize: 14),
),
),
],
),
);
}
}
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
// circle_slider.dart
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/model/model_movie.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: () {},
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
// box_slider.dart
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/model/model_movie.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: () {},
child: Container(
padding: EdgeInsets.only(right: 10),
child: Align(
alignment: Alignment.centerLeft,
child: Image.asset('images/' + movies[i].poster),
),
),
));
}
return results;
}

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

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

Author

TaeBbong Kwon

Posted on

2020-03-23

Updated on

2022-08-06

Licensed under

Comments