flutter_pagewise icon indicating copy to clipboard operation
flutter_pagewise copied to clipboard

List refresh

Open pilotviper134 opened this issue 5 years ago • 2 comments

Hello,

I have normal list with comments in my app.

Widget ShowComments() { return PagewiseListView( pageSize: PAGE_SIZE, physics: const AlwaysScrollableScrollPhysics(), loadingBuilder: (context) { return Container( child: Center( child: Container( child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>(Colors.white), ), height: 50.0, width: 50.0, ) ), height: MediaQuery.of(context).size.height - 160, width: MediaQuery.of(context).size.width, ); }, noItemsFoundBuilder: (context) { return Container( child: Center( child: Text( 'Brak komentarzy w tym momencie.', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold), textAlign: TextAlign.center, ), ), height: MediaQuery.of(context).size.height - 160, width: MediaQuery.of(context).size.width, ); }, retryBuilder: (context, callback) { return Button( child: Text( 'Spróbuj ponownie', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold), textAlign: TextAlign.center, ), gradient: LinearGradient( colors: <Color>[ Color.fromRGBO(247, 131, 97, 1.0), Color.fromRGBO(245, 75, 100, 1.0) ], ), onPressed: () => callback(), ); }, itemBuilder: (context, entry, index) { return getWidget(widget.userResult, widget.postData, entry); }, pageFuture: (pageIndex) { currentPage = pageIndex; commentsFuture = getComments(widget.userResult, widget.postData, currentPage * PAGE_SIZE, PAGE_SIZE); return commentsFuture; }, ); }

I adding to list using

Future<List<Comment>> getComments(UserResult userResult, Post postData, int offset, int limit) async { var head = {"Authorization": userResult.user.token}; Map response = await ServerManager.instance.SendFuture("api/v1/comments/get/${userResult.user.id}/${postData.id}", {"offset": offset, "limit": limit}, head); CommentsResult commentsResult = CommentsResult.fromJson(response); return commentsResult.comments; }

Unfortunately, adding an item to the list the list does not refresh. I used StatefulWidget

pilotviper134 avatar Nov 12 '19 18:11 pilotviper134

I will add that the items on the list are downloaded from the server and they download the content when they first enter the screen. Everything works nicely. The problem is that on the same screen the user can leave a comment. after leaving a comment, the list will not be refreshed until I leave and enter the screen again, my added comment will be shown. How to fix it?

pilotviper134 avatar Nov 12 '19 18:11 pilotviper134

@pilotviper134 you can extend PagewiseLoadController and create there a method like void insertItem(int position, T item) { this.loadedItems.insert(position, item); this.notifyListeners(); } This will allow you to update UI after adding a comment. Issue can be closed

mishatron avatar Mar 21 '20 19:03 mishatron