Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit cd762642 authored by dleurs's avatar dleurs
Browse files

Better Intermediary result - GridView BottonLoader solved by incrasinf item Counter

parent ee8351d1
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,6 @@ class PostpicturesBloc extends Bloc<PostpicturesEvent, PostpicturesState> {
@override
Stream<PostpicturesState> mapEventToState(PostpicturesEvent event) async* {
if (event is PostpicturesFetched) {
print(state);
yield await _mapPostFetchedToState(state);
}
}
......@@ -33,18 +32,22 @@ class PostpicturesBloc extends Bloc<PostpicturesEvent, PostpicturesState> {
if (state is PostpicturesInitial) {
final movies = await _fetchMoviesOfAPage(page: 1);
return PostpicturesSuccess(
movies: movies, hasReachedMax: false, page: 1);
// TODO: Break point here
movies: movies,
hasReachedMax: false,
page: 1);
}
final movies = await _fetchMoviesOfAPage(page: state.page + 1);
int newPage = state.page + 1;
final movies = await _fetchMoviesOfAPage(page: newPage);
return movies.isEmpty
? PostpicturesSuccess(
movies: List.of(state.movies)..addAll(movies),
hasReachedMax: false,
page: state.page + 1)
hasReachedMax: true,
page: newPage)
: PostpicturesSuccess(
movies: List.of(state.movies)..addAll(movies),
hasReachedMax: false,
page: state.page + 1);
page: newPage);
} on Exception {
return PostpicturesFailure(
movies: state.movies,
......
......@@ -5,7 +5,7 @@ class Movie {
String posterPath;
Image image;
Movie({@required this.title, @required this.posterPath});
//Movie({@required this.title, @required this.posterPath});
Movie.fromJson(jsonResult) {
title = jsonResult['title'];
......
import 'package:bloc_pattern/bloc/postPictures/postpictures_bloc.dart';
import 'package:bloc_pattern/ui/components/bottom_loader.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class PostsList extends StatefulWidget {
......@@ -36,8 +37,8 @@ class _PostsListState extends State<PostsList> {
}
return GridView.builder(
itemCount: state.hasReachedMax
? state.movies.length
: state.movies.length + 1,
? state.movies.length + 1
: state.movies.length + 2,
controller: _scrollController,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),
......@@ -50,17 +51,24 @@ class _PostsListState extends State<PostsList> {
loadingBuilder: (context, child, loadingProgress) {
return loadingProgress == null
? child
: Column(
children: [
Text(state.movies[index].title),
LinearProgressIndicator(
value: loadingProgress.expectedTotalBytes !=
null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes
: null,
),
],
: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text(state.movies[index].title,
style: TextStyle(
fontSize: 20,
)),
LinearProgressIndicator(
value: loadingProgress.expectedTotalBytes !=
null
? loadingProgress
.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes
: null,
),
],
),
);
});
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment