Last active
May 24, 2020 22:42
-
-
Save surapuramakhil/5dbbc060c92557c18ecab6e2dc9b9cbd to your computer and use it in GitHub Desktop.
FireStore Issue - getting instance of Document on builder callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cloud_firestore/cloud_firestore.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/painting.dart'; | |
import 'package:flutter/widgets.dart'; | |
import 'package:flutter_tic_tac_toe/storage/game_info_repository.dart'; | |
class VictoriesList extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
Firestore.instance | |
.collection('books') | |
.document() | |
.setData({'title': 'title', 'author': 'author'}); | |
return StreamBuilder<QuerySnapshot>( | |
stream: Firestore.instance | |
.collection(GameInfoRepository.VICTORIES_DOC_NAME) | |
.snapshots(), | |
builder: (context, snapshot) { | |
if (snapshot.hasError) { | |
return new Text('Error: ${snapshot.error}', | |
textDirection: TextDirection.ltr); | |
} | |
switch (snapshot.connectionState) { | |
case ConnectionState.waiting: | |
return new Text( | |
'Loading...', | |
textDirection: TextDirection.ltr, | |
); | |
default: | |
if (!snapshot.hasData) { | |
print("No Data"); | |
return new Text( | |
"No Data", | |
textDirection: TextDirection.ltr, | |
); | |
} | |
return new ListView( | |
children: | |
snapshot.data.documents.map((DocumentSnapshot document) { | |
print("-----------Document:$document" + document.toString()); | |
return new ListTile( | |
title: new Text(document['title']), | |
subtitle: new Text(document['author']), | |
); | |
}).toList(), | |
); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am facing this Issue. Below is the output.
I have written bold text of print statement on line 41.
Performing hot reload...
Syncing files to device ONEPLUS A6000...
D/DecorView(27652): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@eb74a17[MainActivity]
Reloaded 2 of 508 libraries in 4,885ms.
I/flutter (27652): -----------Document:Instance of 'DocumentSnapshot'Instance of 'DocumentSnapshot'
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building StreamBuilder(dirty, state: _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot>#75baa):
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 298 pos 10: 'data != null'
The relevant error-causing widget was:
StreamBuilder file:///home/akhil-kfn/AndroidStudioProjects/flutter-tic-tac-toe/lib/storage/fireStore.dart:15:12
When the exception was thrown, this was the stack:
#2 new Text (package:flutter/src/widgets/text.dart:298:10)
#3 VictoriesList.build.. (package:flutter_tic_tac_toe/storage/fireStore.dart:43:32)
#4 MappedListIterable.elementAt (dart:_internal/iterable.dart:417:31)
#5 ListIterable.toList (dart:_internal/iterable.dart:221:19)
#6 VictoriesList.build. (package:flutter_tic_tac_toe/storage/fireStore.dart:46:20)
...
════════════════════════════════════════════════════════════════════════════════════════════════════