Closed rrifafauzikomara closed 3 years ago
Hi, @rrifafauzikomara
Maybe you could try this
In your BLoc
try { if (state.status == LogAttendanceStatus.initial) { final response = await apiService.getLogAttendance(1, 10); return state.copyWith( status: LogAttendanceStatus.success, data: response.data.data, //Update yours to This one hasReachedMax: response.data.data.length <= 10 ? true : false, ); } final response = await apiService.getLogAttendance(state.data.length, 10); return response.data.data.isEmpty ? state.copyWith(hasReachedMax: true) : state.copyWith( status: LogAttendanceStatus.success, data: List.of(state.data)..addAll(response.data.data), //Update yours to This one hasReachedMax: response.data.data.length <= 10 ? true : false, ); } on Exception { return state.copyWith(status: LogAttendanceStatus.failure); }
In your UI
itemBuilder: (BuildContext context, int index) { //Update yours to This one return index >= state.data.length && !state.hasReachedMax ? Center(child: CircularProgressIndicator()) : Card( child: Padding( padding: const EdgeInsets.all(8.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text("Date: ${state.data[index].date}"), Text( "In: ${state.data[index].datumIn}"), Text( "Note In: ${state.data[index].inNote}"), Text("Out: ${state.data[index].out} "), Text( "Note Out: ${state.data[index].outNote}"), ], ), ), ); },
Thanks @cemanganas
Thanks @cemanganas
Sama Sama Mas Bro @rrifafauzikomara 👍
First of all, I already try your example of Infinite List from here (https://github.com/felangel/bloc/tree/master/examples/flutter_infinite_list) and I try to my project. But in my project, it's not like expected like your example because the loading still appears at the bottom of ListView like this.
The length of data is 4 like this bellow, but why the loading still appear it looks like I always scrolled but actually not?
This is my model:
This is my API function:
This is the state:
This is the event:
This is the bloc:
This is the UI:
What I'm missing?