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 e0927fd2 authored by dleurs's avatar dleurs
Browse files

README challenges and problems

parent 96e4a986
Branches bloc_api_optimised_code
No related tags found
No related merge requests found
# BLoC in Flutter to get images from IP and pagination
Biggest challenge of this project :
- Pagination mechanism
- Adapt to the API, is there pages (20 items by API calls) or can you fix the limit in the HTTP call
- Two separate flow of async, get the name and urlImagePath of the picture, and then download the picture
- Download the picture with Image.network or NetworkAssetBundle(Uri.parse(imgUrl)).load("")).buffer.asUint8List() and then Image.memory
- How to load new pages ? by button ? scolling down ? if scrolling, check that the user can scroll down (only one item in the first page, cannot scroll), or he will be stuck
- StreamBuilder ? or BlocBuilder / BlocConsumer ?
![](assets/intermediary-result-3.gif)
Bloc Documentation : https://bloclibrary.dev/#/flutterbloccoreconcepts
API and project from : https://www.themoviedb.org/settings/api?language=fr
......@@ -41,4 +48,7 @@ On 3G<br/>
## Intermediary result 2. commit 92e49a1e47 on branch bloc_api_optimised_code
On 3G<br/>
Loading 20 pictures for every pages takes too much times. Nearly 20 seconds for the first page<br/>
![](assets/intermediary-result-2.gif)
\ No newline at end of file
![](assets/intermediary-result-2.gif)
## Problem when cannot scroll down
![](assets/intermediary-result-4-problem.gif)
assets/intermediary-result-3.gif

3.91 MiB

assets/intermediary-result-4-problem.gif

3.91 MiB

......@@ -65,7 +65,9 @@ class PostpicturesBloc extends Bloc<PostpicturesEvent, PostpicturesState> {
// TODO: Check this step
final data = json.decode(response.body)["results"] as List;
List<Movie> movies = <Movie>[];
for (int i = 0; i < data.length; i++) {
for (int i = 0; i < 2; i++) {
//for (int i = 0; i < data.length; i++) {
// TODO: Reduced 20 to 4, but you don't have all movies !! Just thing themoviedb bad API
Movie movie = await Movie.loadImage(Movie.fromJson(data[i]));
movies.add(movie);
}
......
......@@ -50,45 +50,9 @@ class _PostsListState extends State<PostsList> {
Image.memory(
state.movies[index].image,
fit: BoxFit.cover,
/* loadingBuilder: (context, child, loadingProgress) {
return loadingProgress == null
? child
: 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,
),
],
),
);
}, */
);
},
);
/* return ListView.builder(
itemBuilder: (BuildContext context, int index) {
return index >= state.movies.length
? BottomLoader()
: MovieListItem(movie: state.movies[index]);
},
itemCount: state.hasReachedMax
? state.movies.length
: state.movies.length + 1,
controller: _scrollController,
); */
} else {
return const Center(child: CircularProgressIndicator());
}
......@@ -109,6 +73,7 @@ class _PostsListState extends State<PostsList> {
bool get _isBottom {
if (!_scrollController.hasClients) return false;
final maxScroll = _scrollController.position.maxScrollExtent;
final double height = MediaQuery.of(context).size.height;
final currentScroll = _scrollController.offset;
return currentScroll >= (maxScroll * 0.9);
}
......
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