@@ -4,7 +4,7 @@ typedef ChildBuilder<T extends sdk.ParseObject> = Widget Function(
4
4
BuildContext context, sdk.ParseLiveListElementSnapshot <T > snapshot);
5
5
6
6
typedef StreamGetter <T extends sdk.ParseObject > = Stream <T > Function ();
7
- typedef DataGetter <T extends sdk.ParseObject > = T Function ();
7
+ typedef DataGetter <T extends sdk.ParseObject > = T ? Function ();
8
8
9
9
class ParseLiveListWidget <T extends sdk.ParseObject > extends StatefulWidget {
10
10
const ParseLiveListWidget ({
@@ -68,7 +68,8 @@ class ParseLiveListWidget<T extends sdk.ParseObject> extends StatefulWidget {
68
68
} else if (snapshot.hasData) {
69
69
child = ListTile (
70
70
title: Text (
71
- snapshot.loadedData! .get <String >(sdk.keyVarObjectId)! ,
71
+ snapshot.loadedData? .get <String >(sdk.keyVarObjectId) ??
72
+ 'Missing Data!' ,
72
73
),
73
74
);
74
75
} else {
@@ -99,35 +100,37 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
99
100
setState (() {
100
101
_noData = livelist.size == 0 ;
101
102
_liveList = livelist;
102
- _liveList! .stream
103
- .listen ((sdk.ParseLiveListEvent <sdk.ParseObject > event) {
104
- if (event is sdk.ParseLiveListAddEvent ) {
105
- if (_animatedListKey.currentState != null ) {
106
- _animatedListKey.currentState!
107
- .insertItem (event.index, duration: widget.duration);
103
+ livelist.stream.listen ((sdk.ParseLiveListEvent <sdk.ParseObject > event) {
104
+ final AnimatedListState ? animatedListState =
105
+ _animatedListKey.currentState;
106
+ if (animatedListState != null ) {
107
+ if (event is sdk.ParseLiveListAddEvent ) {
108
+ animatedListState.insertItem (event.index,
109
+ duration: widget.duration);
110
+
111
+ setState (() {
112
+ _noData = livelist.size == 0 ;
113
+ });
114
+ } else if (event is sdk.ParseLiveListDeleteEvent ) {
115
+ animatedListState.removeItem (
116
+ event.index,
117
+ (BuildContext context, Animation <double > animation) =>
118
+ ParseLiveListElementWidget <T >(
119
+ key: ValueKey <String >(
120
+ event.object.get <String >(sdk.keyVarObjectId) ??
121
+ 'removingItem' ),
122
+ childBuilder: widget.childBuilder ??
123
+ ParseLiveListWidget .defaultChildBuilder,
124
+ sizeFactor: animation,
125
+ duration: widget.duration,
126
+ loadedData: () => event.object as T ,
127
+ preLoadedData: () => event.object as T ,
128
+ ),
129
+ duration: widget.duration);
130
+ setState (() {
131
+ _noData = livelist.size == 0 ;
132
+ });
108
133
}
109
- setState (() {
110
- _noData = livelist.size == 0 ;
111
- });
112
- } else if (event is sdk.ParseLiveListDeleteEvent ) {
113
- _animatedListKey.currentState! .removeItem (
114
- event.index,
115
- (BuildContext context, Animation <double > animation) =>
116
- ParseLiveListElementWidget <T >(
117
- key: ValueKey <String >(event.object.get <String >(
118
- sdk.keyVarObjectId,
119
- defaultValue: 'removingItem' )! ),
120
- childBuilder: widget.childBuilder ??
121
- ParseLiveListWidget .defaultChildBuilder,
122
- sizeFactor: animation,
123
- duration: widget.duration,
124
- loadedData: () => event.object as T ,
125
- preLoadedData: () => event.object as T ,
126
- ),
127
- duration: widget.duration);
128
- setState (() {
129
- _noData = livelist.size == 0 ;
130
- });
131
134
}
132
135
});
133
136
});
@@ -143,7 +146,8 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
143
146
144
147
@override
145
148
Widget build (BuildContext context) {
146
- if (_liveList == null ) {
149
+ final sdk.ParseLiveList <T >? liveList = _liveList;
150
+ if (liveList == null ) {
147
151
return widget.listLoadingElement ?? Container ();
148
152
} else {
149
153
return Stack (
@@ -154,8 +158,7 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
154
158
duration: widget.duration,
155
159
child: widget.queryEmptyElement,
156
160
),
157
- //_liveList isn't (checked above)
158
- buildAnimatedList (_liveList! ),
161
+ buildAnimatedList (liveList),
159
162
],
160
163
);
161
164
}
@@ -184,8 +187,8 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
184
187
return ParseLiveListElementWidget <T >(
185
188
key: ValueKey <String >(liveList.getIdentifier (index)),
186
189
stream: () => liveList.getAt (index),
187
- loadedData: () => liveList.getLoadedAt (index)! ,
188
- preLoadedData: () => liveList.getPreLoadedAt (index)! ,
190
+ loadedData: () => liveList.getLoadedAt (index),
191
+ preLoadedData: () => liveList.getPreLoadedAt (index),
189
192
sizeFactor: animation,
190
193
duration: widget.duration,
191
194
childBuilder:
0 commit comments