@@ -4,7 +4,7 @@ typedef ChildBuilder<T extends sdk.ParseObject> = Widget Function(
44 BuildContext context, sdk.ParseLiveListElementSnapshot <T > snapshot);
55
66typedef 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 ();
88
99class ParseLiveListWidget <T extends sdk.ParseObject > extends StatefulWidget {
1010 const ParseLiveListWidget ({
@@ -68,7 +68,8 @@ class ParseLiveListWidget<T extends sdk.ParseObject> extends StatefulWidget {
6868 } else if (snapshot.hasData) {
6969 child = ListTile (
7070 title: Text (
71- snapshot.loadedData! .get <String >(sdk.keyVarObjectId)! ,
71+ snapshot.loadedData? .get <String >(sdk.keyVarObjectId) ??
72+ 'Missing Data!' ,
7273 ),
7374 );
7475 } else {
@@ -99,35 +100,37 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
99100 setState (() {
100101 _noData = livelist.size == 0 ;
101102 _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+ });
108133 }
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- });
131134 }
132135 });
133136 });
@@ -143,7 +146,8 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
143146
144147 @override
145148 Widget build (BuildContext context) {
146- if (_liveList == null ) {
149+ final sdk.ParseLiveList <T >? liveList = _liveList;
150+ if (liveList == null ) {
147151 return widget.listLoadingElement ?? Container ();
148152 } else {
149153 return Stack (
@@ -154,8 +158,7 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
154158 duration: widget.duration,
155159 child: widget.queryEmptyElement,
156160 ),
157- //_liveList isn't (checked above)
158- buildAnimatedList (_liveList! ),
161+ buildAnimatedList (liveList),
159162 ],
160163 );
161164 }
@@ -184,8 +187,8 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
184187 return ParseLiveListElementWidget <T >(
185188 key: ValueKey <String >(liveList.getIdentifier (index)),
186189 stream: () => liveList.getAt (index),
187- loadedData: () => liveList.getLoadedAt (index)! ,
188- preLoadedData: () => liveList.getPreLoadedAt (index)! ,
190+ loadedData: () => liveList.getLoadedAt (index),
191+ preLoadedData: () => liveList.getPreLoadedAt (index),
189192 sizeFactor: animation,
190193 duration: widget.duration,
191194 childBuilder:
0 commit comments