Basically, I want to display info admin in the section drawer. So I user StreamBuilder
. Then I got an error inline
StreamBuilder<DocumentSnapshot> file:///D:/Android_project/finalyearproject/lib/sidebar/AdminDrawer.dart:26:12
Here my AdminDrawer class
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:finalyearproject/screen/login.dart';
import 'package:finalyearproject/service/auth.dart';
class AdminDrawer extends StatefulWidget {
final String uid ;
AdminDrawer({ this.uid });
@override
_AdminDrawerState createState() => _AdminDrawerState();
}
class _AdminDrawerState extends State<AdminDrawer> {
final AuthService _authService = AuthService();
@override
Widget build(BuildContext context) {
return StreamBuilder( **//this line show the error.**
stream: Firestore.instance.collection('Admin').document(widget.uid).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
} else {
return Drawer(
child: Column(
children: <Widget>[
Container(
width: double.infinity,
padding: EdgeInsets.only(top: 40),
color: Colors.redAccent,
child: Center(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 40),
width: 100,
height: 100,
),
(snapshot.data['name']),
Text(snapshot.data['email']),
],
),
),
),
SizedBox(height: 5.0),
ListTile(
leading: Icon(Icons.person_pin),
title: Text('Profile Admin'),
onTap: () async {
**// this area I will use the nagivator push data of info admin for updating profile. This part I will pass the data to other screen//**
},
),
SizedBox(height: 5.0),
ListTile(
leading: Icon(Icons.arrow_back),
title: Text('Logout'),
onTap: () async {
await _authService.signOut();
Navigator.push(context,
MaterialPageRoute(
builder: (context) => LoginScreen()));
}
),
],
),
);
}
}
);
}
}
So I need someone to help me for solve this problem. Is there anything that I missed?
It seems your snapshot.data is null. Be sure that you have data. And I assume that your snapshot.data['name'] is not a widget. So, you must comment on that line. You can use it in a widget like this: