Skip to content

Commit 5554a3f

Browse files
committed
Create list categories
1 parent f4e447a commit 5554a3f

File tree

8 files changed

+97
-1
lines changed

8 files changed

+97
-1
lines changed
12.8 KB
Loading
25.8 KB
Loading
39.4 KB
Loading
11.3 KB
Loading

lib/res/color_app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import 'package:flutter/material.dart';
22

33
class ColorApp {
44
static const primaryColor = Color(0xFFDF3D54);
5+
static const primaryDarkColor = Color(0xFFB21418);
56
static const accentColor = Color(0xFFEDE5DC);
67
}

lib/src/model/category/category.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
part 'category.g.dart';
3+
4+
@JsonSerializable()
5+
class Category {
6+
String title;
7+
String backdropPath;
8+
9+
Category({this.title, this.backdropPath});
10+
11+
factory Category.fromJson(Map<String, dynamic> json) =>
12+
_$CategoryFromJson(json);
13+
14+
Map<String, dynamic> toJson() => _$CategoryToJson(this);
15+
16+
@override
17+
String toString() {
18+
return 'Category{title: $title, backdropPath: $backdropPath}';
19+
}
20+
}

lib/src/ui/home/home_screen.dart

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_ui_cinemax/src/model/banner_movie.dart';
2+
import 'package:flutter_ui_cinemax/res/color_app.dart';
3+
import 'package:flutter_ui_cinemax/src/model/banner/banner_movie.dart';
4+
import 'package:flutter_ui_cinemax/src/model/category/category.dart';
35

46
class HomeScreen extends StatefulWidget {
57
@override
@@ -21,6 +23,8 @@ class _HomeScreenState extends State<HomeScreen> {
2123
_buildWidgetAppBar(),
2224
SizedBox(height: 20.0),
2325
_buildWidgetBanner(mediaQuery),
26+
SizedBox(height: 20.0),
27+
_buildWidgetCategories(mediaQuery),
2428
],
2529
),
2630
),
@@ -136,4 +140,75 @@ class _HomeScreenState extends State<HomeScreen> {
136140
),
137141
);
138142
}
143+
144+
Widget _buildWidgetCategories(MediaQueryData mediaQuery) {
145+
var listCategories = [
146+
Category(
147+
title: 'Top Rated',
148+
backdropPath: 'assets/images/top_rated_backdrop_path.jpeg'),
149+
Category(
150+
title: 'Upcoming',
151+
backdropPath: 'assets/images/upcoming_backdrop_path.jpeg'),
152+
Category(
153+
title: 'Now Playing',
154+
backdropPath: 'assets/images/now_playing_backdrop_path.jpeg'),
155+
Category(
156+
title: 'Popular',
157+
backdropPath: 'assets/images/popular_backdrop_path.jpeg'),
158+
];
159+
return Container(
160+
width: mediaQuery.size.width,
161+
height: 60.0,
162+
child: ListView.builder(
163+
scrollDirection: Axis.horizontal,
164+
itemBuilder: (BuildContext context, int index) {
165+
var category = listCategories[index];
166+
return Padding(
167+
padding: EdgeInsets.only(
168+
left: 16.0,
169+
right: index == listCategories.length - 1 ? 16.0 : 0.0,
170+
),
171+
child: Container(
172+
width: 200.0,
173+
decoration: BoxDecoration(
174+
borderRadius: BorderRadius.circular(4.0),
175+
image: DecorationImage(
176+
image: AssetImage(
177+
category.backdropPath,
178+
),
179+
fit: BoxFit.cover,
180+
),
181+
),
182+
child: Stack(
183+
children: <Widget>[
184+
Opacity(
185+
opacity: 0.8,
186+
child: Container(
187+
decoration: BoxDecoration(
188+
borderRadius: BorderRadius.circular(4.0),
189+
color: ColorApp.primaryDarkColor,
190+
),
191+
),
192+
),
193+
Align(
194+
alignment: Alignment.center,
195+
child: Text(
196+
category.title.toUpperCase(),
197+
style: Theme.of(context).textTheme.body1.merge(
198+
TextStyle(
199+
color: Colors.white,
200+
fontWeight: FontWeight.bold,
201+
),
202+
),
203+
),
204+
),
205+
],
206+
),
207+
),
208+
);
209+
},
210+
itemCount: listCategories.length,
211+
),
212+
);
213+
}
139214
}

0 commit comments

Comments
 (0)