I am getting data from firebase and making cards using that data. to display certain data of user from database, the data loads fine but for 1 second or more there is a red error screen. I want this to go away I'll show you my code. can somebody please help show me what's wrong. I have no clue what I am doing wrong that this happens and I get the error
The getter 'uid' was called on null. Receiver: null Tried calling: uid
The method '[]' was called on null. Receiver: null Tried calling:
here is my code, any help will be appreciated thankyou
class CardBuilder extends StatefulWidget {
final String title;
final String text;
final IconData icon;
CardBuilder({Key key, this.title,this.text,this.icon}): super(key: key);
@override
_CardBuilderState createState() => _CardBuilderState();
}
class _CardBuilderState extends State<CardBuilder> {
FirebaseUser user;
String error;
void setUser(FirebaseUser user) {
setState(() {
this.user = user;
this.error = null;
});
}
void setError(e) {
setState(() {
this.user = null;
this.error = e.toString();
});
}
@override
void initState() {
super.initState();
FirebaseAuth.instance.currentUser().then(setUser).catchError(setError);
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance.collection(UserInformation).document(user.uid).snapshots(),
builder: (context, snapshot) {
var userDocument = snapshot.data;
// User userDocument here ..........
return Card(
margin: EdgeInsets.only(left: 20,right: 20,top: 20),
child: ListTile(
leading:
Icon(widget.icon, color: QamaiGreen, size: 20.0),
title: AutoSizeText(
'${widget.title} : ${userDocument[widget.text]}',
style: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.w600,
color: QamaiThemeColor,
fontSize: 15
),
maxLines: 1,
maxFontSize: 15,
minFontSize: 12,
),
));
});
}
}