Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List refresh #82

Open
pilotviper134 opened this issue Nov 12, 2019 · 2 comments
Open

List refresh #82

pilotviper134 opened this issue Nov 12, 2019 · 2 comments

Comments

@pilotviper134
Copy link

pilotviper134 commented Nov 12, 2019

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(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.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> 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
Copy link
Author

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?

@mishatron
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants