2
2
// Use of this source code is governed by the MIT license that can be found
3
3
// in the LICENSE file.
4
4
5
+ import 'dart:async' ;
6
+
5
7
import 'package:betterstatmobile/containers/app_loading.dart' ;
6
8
import 'package:betterstatmobile/containers/schedule_details.dart' ;
7
9
import 'package:betterstatmobile/localization.dart' ;
@@ -18,7 +20,7 @@ class ScheduleList extends StatelessWidget {
18
20
final List <Schedule > schedules;
19
21
final Function (Schedule ) onRemove;
20
22
final Function (Schedule ) onUndoRemove;
21
- final Function () onRefresh;
23
+ Future < Null > Function (Completer < Null > ) onRefresh;
22
24
23
25
ScheduleList ({
24
26
@required this .schedules,
@@ -30,33 +32,42 @@ class ScheduleList extends StatelessWidget {
30
32
@override
31
33
Widget build (BuildContext context) {
32
34
return AppLoading (builder: (context, loading) {
33
- return loading
34
- ? Center (
35
- key: BetterstatKeys .schedulesLoading,
36
- child: CircularProgressIndicator (
37
- key: BetterstatKeys .statsLoading,
38
- ))
39
- : RefreshIndicator (
35
+ return RefreshIndicator (
40
36
key: _refreshIndicatorKey,
41
- onRefresh: () async { await onRefresh ();} ,
42
- child: Container (
43
- child: ListView .builder (
44
- key: BetterstatKeys .scheduleList,
45
- itemCount: schedules.length,
46
- itemBuilder: (BuildContext context, int index) {
47
- final schedule = schedules[index];
37
+ onRefresh: () => onRefresh (Completer < Null >()) ,
38
+ child: Container (
39
+ child: ListView .builder (
40
+ key: BetterstatKeys .scheduleList,
41
+ itemCount: schedules.length,
42
+ itemBuilder: (BuildContext context, int index) {
43
+ final schedule = schedules[index];
48
44
49
- return ScheduleItem (
50
- schedule: schedule,
51
- onTap: () => {},
52
- );
53
- },
54
- ),
55
- ),
56
- );
45
+ return ScheduleItem (
46
+ schedule: schedule,
47
+ onTap: () => {},
48
+ );
49
+ },
50
+ ),
51
+ ),
52
+ );
57
53
});
58
54
}
59
55
56
+ Future waitWhile (bool Function () test,
57
+ [Duration pollInterval = Duration .zero]) {
58
+ var completer = Completer ();
59
+ void check () {
60
+ if (! test ()) {
61
+ completer.complete ();
62
+ } else {
63
+ Timer (pollInterval, check);
64
+ }
65
+ }
66
+
67
+ check ();
68
+ return completer.future;
69
+ }
70
+
60
71
void _removeSchedule (BuildContext context, Schedule schedule) {
61
72
onRemove (schedule);
62
73
@@ -90,7 +101,8 @@ class ScheduleList extends StatelessWidget {
90
101
key: BetterstatKeys .snackbar,
91
102
duration: Duration (seconds: 2 ),
92
103
content: Text (
93
- BetterstatLocalizations .of (context).scheduleDeleted (schedule.name),
104
+ BetterstatLocalizations .of (context)
105
+ .scheduleDeleted (schedule.name),
94
106
maxLines: 1 ,
95
107
overflow: TextOverflow .ellipsis,
96
108
),
0 commit comments