Commit 2a79e737 authored by Ardi Baskoro's avatar Ardi Baskoro
Browse files

Implement Bloc at HomePage

parent 1b3c6c28
import 'package:flutter_modular/network/model/movie.dart';
import 'package:flutter_modular/repository/repository.dart';
import 'package:rxdart/rxdart.dart';
class MovieListBloc {
final _repository = Repository();
final _movieFetcher = PublishSubject<Movie>();
Stream<Movie> get allMovie => _movieFetcher.stream;
fetchAllMovie() async {
Movie movie = await _repository.fetchAllMovie();
_movieFetcher.sink.add(movie);
}
dispose() {
_movieFetcher.close();
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:flutter_modular/ui/home_page.dart';
import 'package:flutter_modular/ui/page/home_page.dart';
void main() => runApp(const MyApp());
......
import 'package:flutter_modular/network/api/api_provider.dart';
import 'package:flutter_modular/network/model/movie.dart';
class Repository {
final apiProvider = ApiProvider();
Future<Movie> fetchAllMovie() => apiProvider.getMovieList();
}
import 'package:flutter/material.dart';
import 'package:flutter_modular/widget/movie_detail_header.dart';
import 'package:flutter_modular/widget/story_line.dart';
import '../widget/movie_detail_header.dart';
import '../widget/story_line.dart';
class DetailPage extends StatelessWidget {
final List<Widget> genre;
......
import 'package:flutter/material.dart';
import 'package:flutter_modular/network/api/api_provider.dart';
import 'package:flutter_modular/network/model/movie.dart';
import 'package:flutter_modular/ui/detail_page.dart';
import 'package:flutter_modular/widget/card_list_movie.dart';
import 'package:flutter_modular/widget/chip_genre_movie.dart';
import 'package:flutter_modular/ui/page/detail_page.dart';
import '../../bloc/movie_list_bloc.dart';
import '../widget/card_list_movie.dart';
import '../widget/chip_genre_movie.dart';
class HomePage extends StatefulWidget {
final String title;
......@@ -15,6 +16,20 @@ class HomePage extends StatefulWidget {
}
class _HomePageState extends State<HomePage> {
final bloc = MovieListBloc();
@override
void initState() {
super.initState();
bloc.fetchAllMovie();
}
@override
void dispose() {
bloc.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -35,8 +50,8 @@ class _HomePageState extends State<HomePage> {
getListMovie() {
return Center(
child: FutureBuilder(
future: ApiProvider().getMovieList(),
child: StreamBuilder(
stream: bloc.allMovie,
builder: (context, AsyncSnapshot<Movie> snapshot) {
if (snapshot.hasData) {
return showListMovie(snapshot);
......
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/common/color_helper.dart';
import '../common/color_helper.dart';
class CardListMovies extends StatelessWidget {
final String image;
......@@ -61,8 +62,7 @@ class CardListMovies extends StatelessWidget {
height: 40,
decoration: BoxDecoration(
color: Colors.blueGrey,
borderRadius:
BorderRadius.circular(20)),
borderRadius: BorderRadius.circular(20)),
),
),
Center(
......@@ -71,10 +71,9 @@ class CardListMovies extends StatelessWidget {
height: 30,
child: CircularProgressIndicator(
strokeWidth: 3.0,
valueColor:
AlwaysStoppedAnimation<Color>(
VoteColorHelper.getColor(
double.parse(vote))),
valueColor: AlwaysStoppedAnimation<Color>(
VoteColorHelper.getColor(
double.parse(vote))),
backgroundColor: Colors.grey,
value: double.parse(vote) / 10.0,
)),
......@@ -111,8 +110,7 @@ class CardListMovies extends StatelessWidget {
title,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 20),
fontWeight: FontWeight.w600, fontSize: 20),
),
Text(
releaseDate,
......
import 'package:flutter/material.dart';
import 'package:flutter_modular/widget/arc_banner_image.dart';
import 'package:flutter_modular/widget/poster.dart';
import 'package:flutter_modular/widget/rating_information.dart';
import '../widget/arc_banner_image.dart';
import '../widget/poster.dart';
import '../widget/rating_information.dart';
class MovieDetailHeader extends StatelessWidget {
final List<Widget> genre;
......
......@@ -264,7 +264,7 @@ packages:
source: hosted
version: "4.2.4"
rxdart:
dependency: transitive
dependency: "direct main"
description:
name: rxdart
url: "https://pub.dartlang.org"
......
......@@ -30,6 +30,7 @@ dependencies:
flutter:
sdk: flutter
http: ^0.13.4
rxdart: ^0.27.3
cached_network_image: ^3.2.0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment