background-refresh after resume()

This commit is contained in:
Mike Schwörer 2024-06-15 17:19:23 +02:00
parent c4773d7b97
commit c68a53e4cd
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

@ -27,6 +27,8 @@ class MessageListPage extends StatefulWidget {
class _MessageListPageState extends State<MessageListPage> with RouteAware { class _MessageListPageState extends State<MessageListPage> with RouteAware {
static const _pageSize = 128; static const _pageSize = 128;
late final AppLifecycleListener _lifecyleListener;
PagingController<String, Message> _pagingController = PagingController.fromValue(PagingState(nextPageKey: null, itemList: [], error: null), firstPageKey: '@start'); PagingController<String, Message> _pagingController = PagingController.fromValue(PagingState(nextPageKey: null, itemList: [], error: null), firstPageKey: '@start');
Map<String, Channel>? _channels = null; Map<String, Channel>? _channels = null;
@ -40,6 +42,10 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
_pagingController.addPageRequestListener(_fetchPage); _pagingController.addPageRequestListener(_fetchPage);
if (widget.isVisiblePage && !_isInitialized) _realInitState(); if (widget.isVisiblePage && !_isInitialized) _realInitState();
_lifecyleListener = AppLifecycleListener(
onResume: _onLifecycleResume,
);
} }
@override @override
@ -91,6 +97,7 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
ApplicationLog.debug('MessageListPage::dispose'); ApplicationLog.debug('MessageListPage::dispose');
Navi.modalRouteObserver.unsubscribe(this); Navi.modalRouteObserver.unsubscribe(this);
_pagingController.dispose(); _pagingController.dispose();
_lifecyleListener.dispose();
super.dispose(); super.dispose();
} }
@ -105,6 +112,11 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
_backgroundRefresh(false); _backgroundRefresh(false);
} }
void _onLifecycleResume() {
ApplicationLog.debug('[MessageList::_onLifecycleResume] --> (will background-refresh)');
_backgroundRefresh(false);
}
Future<void> _fetchPage(String thisPageToken) async { Future<void> _fetchPage(String thisPageToken) async {
final acc = Provider.of<AppAuth>(context, listen: false); final acc = Provider.of<AppAuth>(context, listen: false);