Skip to content

LiveQuery: list is null fixes #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/src/utils/parse_live_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class ParseLiveList<T extends ParseObject> {
final ParseResponse parseResponse = await _runQuery();
if (parseResponse.success) {
_list = parseResponse.results
.map<ParseLiveListElement<T>>(
?.map<ParseLiveListElement<T>>(
(dynamic element) => ParseLiveListElement<T>(element))
.toList();
?.toList() ?? List<ParseLiveListElement<T>>();
}

LiveQuery()
Expand All @@ -112,9 +112,9 @@ class ParseLiveList<T extends ParseObject> {
.getClientEventStream
.listen((LiveQueryClientEvent event) async {
if (event == LiveQueryClientEvent.CONNECTED) {
ParseResponse parseResponse = await _runQuery();
final ParseResponse parseResponse = await _runQuery();
if (parseResponse.success) {
List<T> newlist = parseResponse.results;
final List<T> newList = parseResponse.results ?? List<T>();

//update List
for (int i = 0; i < _list.length; i++) {
Expand All @@ -124,21 +124,21 @@ class ParseLiveList<T extends ParseObject> {

bool stillInList = false;

for (int j = 0; j < newlist.length; j++) {
if (newlist[j].get<String>(keyVarObjectId) == currentObjectId) {
for (int j = 0; j < newList.length; j++) {
if (newList[j].get<String>(keyVarObjectId) == currentObjectId) {
stillInList = true;
if (newlist[j]
if (newList[j]
.get<DateTime>(keyVarUpdatedAt)
.isAfter(currentObject.get<DateTime>(keyVarUpdatedAt))) {
QueryBuilder<T> queryBuilder = QueryBuilder<T>.copy(_query)
final QueryBuilder<T> queryBuilder = QueryBuilder<T>.copy(_query)
..whereEqualTo(keyVarObjectId, currentObjectId);
queryBuilder.query<T>().then((ParseResponse result) {
if (result.success) {
if (result.success && result.results != null) {
_objectUpdated(result.results.first);
}
});
}
newlist.removeAt(j);
newList.removeAt(j);
j--;
break;
}
Expand All @@ -149,8 +149,8 @@ class ParseLiveList<T extends ParseObject> {
}
}

for (int i = 0; i < newlist.length; i++) {
_objectAdded(newlist[i], loaded: false);
for (int i = 0; i < newList.length; i++) {
_objectAdded(newList[i], loaded: false);
}
}
}
Expand Down Expand Up @@ -208,8 +208,8 @@ class ParseLiveList<T extends ParseObject> {
keyVarObjectId, _list[index].object.get<String>(keyVarObjectId))
..setLimit(1);
final ParseResponse response = await queryBuilder.query<T>();
if (response.success && response.results != null) {
_list[index].object = response.results.first;
if (response.success) {
_list[index].object = response.results?.first;
} else {
_list[index].object = null;
throw response.error;
Expand Down