[MessageSearchListView] Add pullToRefresh
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -425,6 +425,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
direction: SortOption.ASC,
|
direction: SortOption.ASC,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
pullToRefresh: false,
|
||||||
paginationParams: PaginationParams(limit: 20),
|
paginationParams: PaginationParams(limit: 20),
|
||||||
emptyBuilder: (_, query) {
|
emptyBuilder: (_, query) {
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ class MessageSearchBlocState extends State<MessageSearchBloc>
|
|||||||
String query,
|
String query,
|
||||||
PaginationParams pagination,
|
PaginationParams pagination,
|
||||||
}) async {
|
}) async {
|
||||||
if (messageResponses?.isNotEmpty == true) return;
|
|
||||||
_messageResponses.add(null);
|
_messageResponses.add(null);
|
||||||
try {
|
try {
|
||||||
final messages = await _search(
|
final messages = await _search(
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class MessageSearchListView extends StatefulWidget {
|
|||||||
this.itemBuilder,
|
this.itemBuilder,
|
||||||
this.onItemTap,
|
this.onItemTap,
|
||||||
this.showResultCount = true,
|
this.showResultCount = true,
|
||||||
|
this.pullToRefresh = true,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Message String to search on
|
/// Message String to search on
|
||||||
@@ -107,6 +108,9 @@ class MessageSearchListView extends StatefulWidget {
|
|||||||
/// Set it to false to hide total results text
|
/// Set it to false to hide total results text
|
||||||
final bool showResultCount;
|
final bool showResultCount;
|
||||||
|
|
||||||
|
/// Set it to false to disable the pull-to-refresh widget
|
||||||
|
final bool pullToRefresh;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageSearchListViewState createState() => _MessageSearchListViewState();
|
_MessageSearchListViewState createState() => _MessageSearchListViewState();
|
||||||
}
|
}
|
||||||
@@ -281,7 +285,35 @@ class _MessageSearchListViewState extends State<MessageSearchListView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget child;
|
Widget child = ListView.separated(
|
||||||
|
physics: AlwaysScrollableScrollPhysics(),
|
||||||
|
itemCount: items.isNotEmpty ? items.length + 1 : items.length,
|
||||||
|
separatorBuilder: (_, index) {
|
||||||
|
if (widget.separatorBuilder != null) {
|
||||||
|
return widget.separatorBuilder(context, index);
|
||||||
|
}
|
||||||
|
return _separatorBuilder(context, index);
|
||||||
|
},
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index < items.length) {
|
||||||
|
return _listItemBuilder(context, items[index]);
|
||||||
|
}
|
||||||
|
return _buildQueryProgressIndicator(context, messageSearchBloc);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (widget.pullToRefresh) {
|
||||||
|
child = RefreshIndicator(
|
||||||
|
onRefresh: () async => messageSearchBloc.search(
|
||||||
|
filter: widget.filters,
|
||||||
|
sort: widget.sortOptions,
|
||||||
|
query: widget.messageQuery,
|
||||||
|
pagination: widget.paginationParams,
|
||||||
|
messageFilter: widget.messageFilters,
|
||||||
|
),
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
child = LazyLoadScrollView(
|
child = LazyLoadScrollView(
|
||||||
onEndOfPage: () => messageSearchBloc.loadMore(
|
onEndOfPage: () => messageSearchBloc.loadMore(
|
||||||
filter: widget.filters,
|
filter: widget.filters,
|
||||||
@@ -292,22 +324,7 @@ class _MessageSearchListViewState extends State<MessageSearchListView> {
|
|||||||
query: widget.messageQuery,
|
query: widget.messageQuery,
|
||||||
messageFilter: widget.messageFilters,
|
messageFilter: widget.messageFilters,
|
||||||
),
|
),
|
||||||
child: ListView.separated(
|
child: child,
|
||||||
physics: AlwaysScrollableScrollPhysics(),
|
|
||||||
itemCount: items.isNotEmpty ? items.length + 1 : items.length,
|
|
||||||
separatorBuilder: (_, index) {
|
|
||||||
if (widget.separatorBuilder != null) {
|
|
||||||
return widget.separatorBuilder(context, index);
|
|
||||||
}
|
|
||||||
return _separatorBuilder(context, index);
|
|
||||||
},
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index < items.length) {
|
|
||||||
return _listItemBuilder(context, items[index]);
|
|
||||||
}
|
|
||||||
return _buildQueryProgressIndicator(context, messageSearchBloc);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (widget.showResultCount) {
|
if (widget.showResultCount) {
|
||||||
|
|||||||
Reference in New Issue
Block a user