I am taking data from FireStore collection but this is showing issue.
I am trying this-
class _HomePageState extends State<HomePage> {
AuthClass authClass = AuthClass();
final FirebaseAuth auth = FirebaseAuth.instance;
@override
Widget build(BuildContext context) {
String st = "ToDo${auth.currentUser?.uid}";
final Stream<QuerySnapshot> stream =
FirebaseFirestore.instance.collection(st).snapshots();
return Scaffold(
backgroundColor: Colors.black87,
appBar: AppBar(
backgroundColor: Colors.black87,
title: Text(
"Today's Schedule",
style: TextStyle(
fontSize: 34,
fontWeight: FontWeight.bold,
color: Colors.white,
…………………………………………………………………………………………………………..
body: StreamBuilder(
stream: stream,
builder: (context, snapshot) {
return ListView.builder(
itemCount: snapshot.data?.docs.length,
itemBuilder: (context, index) {
IconData iconData;
Color iconColor;
Map<String, dynamic> document =
snapshot.data?.docs[index].data() as Map<String, dynamic>;
switch (document["Category"]) {
case "Work":
iconColor = Colors.red;
iconData = Icons.run_circle_outlined;
break;
case "WorkOut":
iconColor = Colors.teal;
iconData = Icons.alarm;
break;
There is data available on Firestore still its showing Null subtype. My app is working but at some sort of time its giving an error.
2
Answers
I got answer to this.
here in dynamic i decleared as a nullable value then it worked.
It may be due to 2 reason.
First is by adding a data with your stream type in
initialData
of stream.Second is in your
snapShot.data
containnull
value. Check from error console and can fix in the model file Eg:json["address"] ?? ''
like that.