[무작정 플러터 강의노트] 10 찜한 콘텐츠 화면 / 기능 만들기

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
// main.dart
import 'package:flutter/material.dart';
import 'package:netflix_clone_lecture_note/screen/home_screen.dart';
import 'package:netflix_clone_lecture_note/screen/like_screen.dart';
import 'package:netflix_clone_lecture_note/screen/more_screen.dart';
import 'package:netflix_clone_lecture_note/screen/search_screen.dart';
import 'package:netflix_clone_lecture_note/widget/bottom_bar.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
TabController controller;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Bbongflix',
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.black,
accentColor: Colors.white,
),
home: DefaultTabController(
length: 4,
child: Scaffold(
body: TabBarView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
HomeScreen(),
SearchScreen(),
LikeScreen(),
MoreScreen(),
],
),
bottomNavigationBar: Bottom(),
),
),
);
}
}
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
// like_screen.dart
import 'package:cloud_firestore/cloud_firestore.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 LikeScreen extends StatefulWidget {
_LikeScreenState createState() => _LikeScreenState();
}

class _LikeScreenState extends State<LikeScreen> {
Widget _buildBody(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('movie')
.where('like', isEqualTo: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.documents);
},
);
}

Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return Expanded(
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: 1 / 1.5,
padding: EdgeInsets.all(3),
children:
snapshot.map((data) => _buildListItem(context, data)).toList()),
);
}

Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
final movie = Movie.fromSnapshot(data);
return InkWell(
child: Image.network(movie.poster),
onTap: () {
Navigator.of(context).push(MaterialPageRoute<Null>(
fullscreenDialog: true,
builder: (BuildContext context) {
return DetailScreen(movie: movie);
}));
},
);
}

@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(20, 27, 20, 7),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Image.asset(
'images/bbongflix_logo.png',
fit: BoxFit.contain,
height: 25,
),
Container(
padding: EdgeInsets.only(left: 30),
child: Text(
'내가 찜한 콘텐츠',
style: TextStyle(fontSize: 14),
),
)
],
),
),
_buildBody(context)
],
),
);
}
}

[무작정 플러터 강의노트] 10 찜한 콘텐츠 화면 / 기능 만들기

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

Author

TaeBbong Kwon

Posted on

2020-03-23

Updated on

2022-08-06

Licensed under

Comments