-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.dart
200 lines (194 loc) · 5.74 KB
/
app.dart
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:halasat_cinema_mobile/src/const.dart';
import 'package:halasat_cinema_mobile/src/models/featured.dart';
import 'package:halasat_cinema_mobile/src/models/post.dart';
import 'package:halasat_cinema_mobile/src/pages/post_page.dart';
import 'package:halasat_cinema_mobile/src/services/featured.dart';
import 'package:halasat_cinema_mobile/src/services/post.dart';
import 'package:halasat_cinema_mobile/src/services/post_list_category.dart';
import 'package:halasat_cinema_mobile/src/widgets/post_row.dart';
class App extends StatelessWidget {
final Future<Featured> _featured = fetchFeatured();
final List<Widget> _postRows = [
PostRow(
title: 'Latest Posts',
titleBorderColor: Colors.blue,
),
PostRow(
title: 'TV Shows',
titleBorderColor: Colors.purple,
fetchList: fetchPostListCategory,
category: 1,
),
PostRow(
title: 'US Box Office',
titleBorderColor: Colors.cyan,
fetchList: fetchPostListCategory,
category: 10,
),
PostRow(
title: 'Bollywood Movies',
titleBorderColor: Colors.purple,
fetchList: fetchPostListCategory,
category: 3,
),
PostRow(
title: 'Bollywood Shows',
titleBorderColor: Colors.purple,
fetchList: fetchPostListCategory,
category: 8,
),
PostRow(
title: 'Arabic Movies',
titleBorderColor: Colors.brown,
fetchList: fetchPostListCategory,
category: 7,
),
PostRow(
title: 'Arabic Shows',
titleBorderColor: Colors.brown,
fetchList: fetchPostListCategory,
category: 4,
),
PostRow(
title: 'Asian Movies',
titleBorderColor: Colors.green,
fetchList: fetchPostListCategory,
category: 6,
),
PostRow(
title: 'Asian Shows',
titleBorderColor: Colors.green,
fetchList: fetchPostListCategory,
category: 5,
),
PostRow(
title: 'Anime Movies',
titleBorderColor: Colors.amber,
fetchList: fetchPostListCategory,
category: 9,
),
PostRow(
title: 'Anime Shows',
titleBorderColor: Colors.amber,
fetchList: fetchPostListCategory,
category: 2,
),
];
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'HalaSat Cinema',
// theme: ThemeData(primarySwatch: Colors.red),
theme: ThemeData.dark().copyWith(
// primaryColor: Colors.red,
accentColor: Colors.red,
),
home: Scaffold(
body: SafeArea(
bottom: false,
child: ListView(
addAutomaticKeepAlives: true,
children: <Widget>[
_buildSearch(context),
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: FutureBuilder(
future: _featured,
builder:
(BuildContext context, AsyncSnapshot<Featured> snapshot) {
if (snapshot.hasData) {
Featured featured = snapshot.data;
return _buildCarouselSlider(context, featured);
} else
return Align(child: CircularProgressIndicator());
},
),
),
]..addAll(_postRows),
),
),
),
);
}
Padding _buildSearch(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: TextField(
onTap: () {
// TODO: Handle search
},
maxLines: 1,
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
filled: true,
contentPadding: EdgeInsets.only(top: 14.0),
hintText: 'Search movies, tv shows...etc.',
border: InputBorder.none,
// fillColor: Colors.grey.shade200,
),
),
),
);
}
CarouselSlider _buildCarouselSlider(BuildContext context, Featured featured) {
return CarouselSlider(
autoPlay: true,
height: 250.0,
items: featured.featured.map((FeaturedItem item) {
return Builder(
builder: (BuildContext context) {
return _buildFeaturedPost(context, item);
},
);
}).toList(),
);
}
Widget _buildFeaturedPost(BuildContext context, FeaturedItem item) {
return GestureDetector(
child: Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
FadeInImage(
fit: BoxFit.cover,
placeholder: AssetImage('assets/featured-placeholder.jpg'),
image: NetworkImage(
'$kVoduBase/${item.large}',
),
),
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Colors.red.withOpacity(0.9),
Colors.blue.withOpacity(0.5),
],
),
),
),
Positioned(
bottom: 10.0,
left: 10.0,
child: Text(
item.title,
style: TextStyle(fontSize: 15.0),
),
)
],
),
),
onTap: () async {
Post res = await fetchPost(int.parse(item.id));
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
return PostPage(postListItem: res.movies[0],);
} ));
},
);
}
}