Skip to content

Commit

Permalink
Add sliver list
Browse files Browse the repository at this point in the history
  • Loading branch information
msal4 committed Feb 27, 2019
1 parent c9b9f75 commit fd59a16
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 144 deletions.
Binary file added assets/featured-placeholder.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/src/models/featured.dart
Expand Up @@ -7,7 +7,7 @@ part 'featured.g.dart';
abstract class Featured implements Built<Featured, FeaturedBuilder> {
static Serializer<Featured> get serializer => _$featuredSerializer;

BuiltList<FeaturedItem> get featuredItems;
BuiltList<FeaturedItem> get featured;

Featured._();

Expand Down
41 changes: 20 additions & 21 deletions lib/src/models/featured.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

253 changes: 171 additions & 82 deletions lib/src/pages/app.dart
@@ -1,13 +1,89 @@
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';

import 'package:halasat_cinema_mobile/src/widgets/post_row.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,
Expand All @@ -16,96 +92,109 @@ class App extends StatelessWidget {
body: SafeArea(
bottom: false,
child: ListView(
cacheExtent: 100.0,
addAutomaticKeepAlives: true,
children: <Widget>[
_buildSearch(context),
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,
),
),
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());
},
),
),
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,
]..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}',
),
PostRow(
title: 'Anime Movies',
titleBorderColor: Colors.amber,
fetchList: fetchPostListCategory,
category: 9,
),
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Colors.red.withOpacity(0.9),
Colors.blue.withOpacity(0.5),
],
),
),
PostRow(
title: 'Anime Shows',
titleBorderColor: Colors.amber,
fetchList: fetchPostListCategory,
category: 2,
),
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],);
} ));
},
);
}
}

0 comments on commit fd59a16

Please sign in to comment.