mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Automatically refresh the list of memberships
This commit is contained in:
parent
6961694fd2
commit
f31323fe23
@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
abstract class SafeState<T extends StatefulWidget> extends State<T> {
|
||||
final _subscriptions = List<StreamSubscription>();
|
||||
final _timers = List<Timer>();
|
||||
|
||||
bool _unmounted = false;
|
||||
|
||||
@ -19,6 +20,9 @@ abstract class SafeState<T extends StatefulWidget> extends State<T> {
|
||||
// Close subscriptions
|
||||
_subscriptions.forEach((f) => f.cancel());
|
||||
|
||||
// Stop intervals
|
||||
_timers.forEach((f) => f.cancel());
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -52,4 +56,10 @@ abstract class SafeState<T extends StatefulWidget> extends State<T> {
|
||||
if (!_unmounted) cb();
|
||||
});
|
||||
}
|
||||
|
||||
/// Safely mimic the setInterval javascript function
|
||||
void setInterval(int secs, void Function(Timer) cb) {
|
||||
final timer = Timer.periodic(Duration(seconds: secs), cb);
|
||||
_timers.add(timer);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ class MembershipsPanel extends StatefulWidget {
|
||||
|
||||
const _MembershipIconsWidth = 30.0;
|
||||
|
||||
/// TODO : add auto-refresh
|
||||
class _MembershipsPanelState extends SafeState<MembershipsPanel> {
|
||||
final _refreshKey = GlobalKey<RefreshIndicatorState>();
|
||||
MembershipList _membershipList;
|
||||
@ -48,13 +47,13 @@ class _MembershipsPanelState extends SafeState<MembershipsPanel> {
|
||||
});
|
||||
} catch (e, s) {
|
||||
print("Could not load the list of memberships! $e\n$s");
|
||||
setTimeout(5, _refresh);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setInterval(20, (t) => _refresh());
|
||||
_refresh();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user