Related
I have tried all the methods to sign out from firebase auth. I am using Phone number auth in the Flutter app using Firebase but am unable to sign out the user. Every time I restart the app it leads me to the Home page but when I click the Logout button it takes me to the Login page.
What I want is a simple sign-out.
Authentication class
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:food_express/pages/login_signup/login.dart';
class Authentication{
Future<void> logOut(BuildContext context) async {
try {
await FirebaseAuth.instance.signOut().then((value) => {
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => Login()), (route) => false)
});
} catch (e) {
print(e); // TODO: show dialog with error
}
}
}
Profile Widget
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:food_express/constant/constant.dart';
import 'package:food_express/functions/Authentication.dart';
import 'package:food_express/pages/login_signup/login.dart';
import 'package:food_express/pages/order/history_order/history.dart';
import 'package:food_express/pages/order/order.dart';
import 'package:food_express/pages/profile/edit_profile.dart';
import 'package:page_transition/page_transition.dart';
import 'package:food_express/pages/profile/address.dart';
import 'package:food_express/pages/notification.dart';
import "../../constant/globals.dart" as global;
class Profile extends StatelessWidget {
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
logoutDialogue() {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
// return object of type Dialog
return Dialog(
elevation: 0.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Container(
height: 130.0,
padding: EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"You sure want to logout?",
style: headingStyle,
),
SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
InkWell(
onTap: () {
logout(context);
},
child: Container(
width: (width / 3.5),
alignment: Alignment.center,
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(5.0),
),
child: Text(
'Cancel',
style: buttonBlackTextStyle,
),
),
),
InkWell(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => Login()));
},
child: Container(
width: (width / 3.5),
alignment: Alignment.center,
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: primaryColor,
borderRadius: BorderRadius.circular(5.0),
),
child: Text(
'Log out',
style: wbuttonWhiteTextStyle,
),
),
),
],
),
],
),
),
);
},
);
}
return Scaffold(
backgroundColor: scaffoldBgColor,
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: whiteColor,
elevation: 0.0,
title: Text(
'Profile',
style: bigHeadingStyle,
),
),
body: ListView(
children: <Widget>[
InkWell(
onTap: () {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
child: EditProfile()));
},
child: Container(
width: width,
padding: EdgeInsets.all(fixPadding),
color: whiteColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: 70.0,
height: 70.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
image: DecorationImage(
image: NetworkImage(
"https://png.pngtree.com/png-clipart/20200224/original/pngtree-cartoon-color-simple-male-avatar-png-image_5230557.jpg"),
fit: BoxFit.cover,
),
),
),
widthSpace,
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
global.profile.Name.toString(),
style: headingStyle,
),
heightSpace,
Text(
global.profile.PhoneNumber.toString(),
style: lightGreyStyle,
),
],
),
],
),
Icon(
Icons.arrow_forward_ios,
size: 16.0,
color: Colors.grey.withOpacity(0.6),
),
],
),
),
),
Container(
margin: EdgeInsets.all(fixPadding),
padding: EdgeInsets.all(fixPadding),
decoration: BoxDecoration(
color: whiteColor,
borderRadius: BorderRadius.circular(5.0),
boxShadow: <BoxShadow>[
BoxShadow(
blurRadius: 1.5,
spreadRadius: 1.5,
color: Colors.grey[200],
),
],
),
child: Column(
children: <Widget>[
InkWell(
onTap: () {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
child: Notifications()));
},
child: getTile(
Icon(Icons.notifications,
color: Colors.grey.withOpacity(0.6)),
'Notifications'),
),
/* InkWell(
onTap: () {
Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: PaymentMethods()));
},
child: getTile(
Icon(Icons.payment, color: Colors.grey.withOpacity(0.6)),
'Payment Methods'),
),
*/
/*InkWell(
onTap: () {},
child: getTile(
Icon(Icons.local_activity,
color: Colors.grey.withOpacity(0.6)),
'My Vouchers'),
),
*/
InkWell(
onTap: () {},
child: getTile(
Icon(Icons.group_add,
color: Colors.grey.withOpacity(0.6)),
'Invite Friends'),
),
],
),
),
Container(
margin: EdgeInsets.all(fixPadding),
padding: EdgeInsets.all(fixPadding),
decoration: BoxDecoration(
color: whiteColor,
borderRadius: BorderRadius.circular(5.0),
boxShadow: <BoxShadow>[
BoxShadow(
blurRadius: 1.5,
spreadRadius: 1.5,
color: Colors.grey[200],
),
],
),
child: Column(
children: <Widget>[
InkWell(
onTap: () {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
child: Order()));
},
child: getTile(
Icon(Icons.history, color: Colors.grey.withOpacity(0.6)),
'Order History'),
),
InkWell(
onTap: () {},
child: getTile(
Icon(Icons.group, color: Colors.grey.withOpacity(0.6)),
'Become our partner'),
),
InkWell(
onTap: () {},
child: getTile(
Icon(Icons.headset_mic,
color: Colors.grey.withOpacity(0.6)),
'Support'),
),
InkWell(
onTap: () {},
child: getTile(
Icon(Icons.star_rate,
color: Colors.yellow.withOpacity(0.6)),
'Rate our App'),
),
],
),
),
Container(
margin: EdgeInsets.all(fixPadding),
padding: EdgeInsets.all(fixPadding),
decoration: BoxDecoration(
color: whiteColor,
borderRadius: BorderRadius.circular(5.0),
boxShadow: <BoxShadow>[
BoxShadow(
blurRadius: 1.5,
spreadRadius: 1.5,
color: Colors.grey[200],
),
],
),
child: Column(
children: <Widget>[
InkWell(
onTap: logoutDialogue,
child: getTile(
Icon(Icons.exit_to_app,
color: Colors.grey.withOpacity(0.6)),
'Logout'),
),
],
),
),
],
),
);
}
getTile(Icon icon, String title) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 40.0,
width: 40.0,
alignment: Alignment.center,
child: icon,
),
widthSpace,
Text(
title,
style: listItemTitleStyle,
),
],
),
Icon(
Icons.arrow_forward_ios,
size: 16.0,
color: Colors.grey.withOpacity(0.6),
),
],
);
}
void logout(context) {
Authentication _auth = Authentication();
_auth.logOut(context);
// await FirebaseAuth.instance.signOut();
// Navigator.pop(context);
}
}
Check the current user already log or not when log out, and when you use then block, you don't need to use the await keyword.
Future<void> logOut(BuildContext context) async {
try {
final User firebaseUser = await FirebaseAuth.instance.currentUser;
if (firebaseUser != null) {
FirebaseAuth.instance.signOut().then((value) => {
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context)
=> Login()), (route) => false)
});
}
} catch (e) {
print(e); // TODO: show dialog with error
}
}
Future<List<DocumentSnapshot>> getData() async {
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore
.collection("LiveGames")
.where("Title", isEqualTo: "Solo")
.getDocuments();
return qn.documents;
}
I have extracted the data using this function getData() to use it in the FutureBuilder.
FutureBuilder(
future: getData(),
builder: (_, AsyncSnapshot<List<DocumentSnapshot>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Padding(
padding: const EdgeInsets.only(
top: 50,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Center(
child: SpinKitCircle(
color: Color.fromRGBO(91, 74, 127, 10),
size: 50.0,
),
),
],
),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
height: 185,
width: double.infinity,
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10)),
color: Colors.blueGrey.shade800,
),
height: 150,
width: double.infinity,
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedBox(
height: 6,
),
Expanded(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: <Widget>[
Column(
children: <Widget>[
SizedBox(
height: 5,
),
Text("Date",
style: TextStyle(
color: Colors.white,
)),
Text(
snapshot.data[index]
.data["GameDate"],
style: TextStyle(
color: Colors.white,
)),
],
),
Column(
children: <Widget>[
SizedBox(
height: 5,
),
Text("Time",
style: TextStyle(
color: Colors.white,
)),
Text(
snapshot.data[index]
.data["GameTime"],
style: TextStyle(
color: Colors.white,
)),
],
),
Column(
children: <Widget>[
SizedBox(
height: 5,
),
Text("Map",
style: TextStyle(
color: Colors.white,
)),
Text(
snapshot.data[index]
.data["MapName"],
style: TextStyle(
color: Colors.white,
)),
],
),
Column(
children: <Widget>[
SizedBox(
height: 5,
),
Text("Mode",
style: TextStyle(
color: Colors.white,
)),
Text(
snapshot.data[index]
.data["GameMode"],
style: TextStyle(
color: Colors.white,
)),
],
)
],
),
),
Divider(
color: Colors.white,
),
Expanded(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: <Widget>[
Column(
children: <Widget>[
SizedBox(
height: 5,
),
Text("Players Joined",
style: TextStyle(
color: Colors.white,
)),
Text(
"${snapshot.data[index].data["RemainingPlayers"]}",
style: TextStyle(
color: Colors.white,
)),
],
),
Column(
children: <Widget>[
SizedBox(
height: 5,
),
Text("Winning",
style: TextStyle(
color: Colors.white,
)),
Expanded(
child: FlatButton(
child: Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.white,
),
onPressed: () {
showModalBottomSheet(
backgroundColor:
Colors.orange
.shade500,
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.only(
topLeft:
Radius.circular(
15),
topRight:
Radius.circular(
15),
)),
context: context,
builder: (context) {
return Container(
child: Column(
children: <Widget>[
],
),
);
},
);
}))
],
),
Column(
children: <Widget>[
SizedBox(
height: 5,
),
Text("Remaining Players",
style: TextStyle(
color: Colors.white,
)),
Text(
"${snapshot.data[index].data["TotalSeats"]}",
style: TextStyle(
color: Colors.white,
)),
],
)
],
),
),
Divider(
color: Colors.white,
),
Expanded(
child: Container(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: <Widget>[
Column(
children: <Widget>[
Text("Per Kill",
style: TextStyle(
color: Colors.white,
)),
Text(
"₹ ${snapshot.data[index].data["PerKill"]}",
style: TextStyle(
color: Colors.white,
)),
],
),
Column(
children: <Widget>[
Text("Entry Fees",
style: TextStyle(
color: Colors.white,
)),
Text(
"₹ ${snapshot.data[index].data["Entryfees"]}",
style: TextStyle(
color: Colors.white,
)),
],
),
],
),
),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 150),
height: 35,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
color: Colors.orange,
),
child: Padding(
padding: const EdgeInsets.only(left: 125),
child: InkWell(
onTap: () {
print("Solo Joined");
},
child: Text(
"Join Contest",
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontFamily: "OpenSans",
fontWeight: FontWeight.bold,
),
),
),
),
),
],
),
),
],
),
);
});
}
},
),
And then i have displayed some Widgets according to the data.
But in database i have some rank values and i want to display the data in the bottomsheet if the rank from 2 to 10 and 11 to 20 and 21 to 40 are zeros i do not want to display in the bottom sheet only rank1 player i want it to display but if Rank1 player and all the players from rank 1 to 40 some values are there then i have to display the all the data in the bottomSheet
From your question, I don't see any issues on using FutureBuilder in Flutter. The issue here seems to lean more on how you can manage your Firestore data to be displayed.
If you'd like to filter out Players to be displayed base from their Rank. What you can do here is create a Collections for Players where you can sort them by Rank.
Say you'd only like to display Players with Rank 1 in your List.
FirebaseFirestore.instance
.collection('players')
.where('rank', isEqualTo: 1)
.snapshots()
For Rank with ranges, say Ranks 2-10, compound queries can be utilized. For querying in Flutter, you can check the API reference for its equivalence.
FirebaseFirestore.instance
.collection('players')
.where('rank', isGreaterThanOrEqualTo: 2)
.where('rank', isLessThanOrEqualTo: 10)
.snapshots()
Here's a sample that I posted previously that filters and displays all carModels base from the selected carMake. It uses StreamBuilder though. I'm curious on your choice for using FutureBuilder instead of StreamBuilder.
Try the following example:
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FutureBuilder<QuerySnapshot>(
future: FirebaseFirestore
.instance
.collection('users') // 👈 Your collection name here
.get(),
builder: (_, snapshot) {
if (snapshot.hasError) return Text('Error = ${snapshot.error}');
if (snapshot.connectionState == ConnectionState.waiting) {
return const Text("Loading");
}
return ListView(
children: snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data = document.data()! as Map<String, dynamic>;
return ListTile(
title: Text(data['avatar']), // 👈 Your valid data here
);
}).toList());
},
)),
);
}
Also refer: How to use StreamBuilder and FutureBuilder for single and multiple documents
how to print value of field.
what I have tried :
print(documents[index].data['Likes.$usersId']);
actually I need this for toggle between icons.
thanks.
Update:
Widget build(BuildContext context) {
return Container(
child: StreamBuilder<QuerySnapshot>(
stream: UserManagement().getPostsStream(),
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else {
final List<DocumentSnapshot> documents = snapshot.data.documents;
return ListView.builder(
itemCount: documents.length,
itemBuilder: (_, index) {
return Card(
elevation: 4,
child: Padding(
padding: EdgeInsets.only(left: 10.0, top: 10),
child: InkWell(
onTap: () => navigateToDetail(
documents[index],
documents[index].data["Userid"],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
children: <Widget>[
Container(
width: 45,
height: 45,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
documents[index].data["User Pic"]),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(
Radius.circular(50.5)),
),
),
Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
documents[index].data["Name"],
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18),
),
),
],
),
Padding(
padding: EdgeInsets.only(left: 60, bottom: 10),
child: Text(
DateFormat.yMMMd().add_jm().format(
DateTime.parse(documents[index]
.data["Creation Time"]
.toDate()
.toString())),
style: TextStyle(
color: Colors.black38, fontSize: 12),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(left: 75, right: 15),
child: Text(
documents[index].data["Description"],
style: TextStyle(fontSize: 16),
),
),
),
Padding(
padding: EdgeInsets.only(
left: 75, top: 15, bottom: 8),
child: Text(
documents.length.toString() +
"Files uploaded",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 14,
fontStyle: FontStyle.italic),
),
),
Divider(),
new Row(
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
IconButton(
onPressed: () {
print(documents[index].data['Likes.$usersId']);
},
icon: documents[index].data['$usersId'] == true ? Icon(Icons.favorite,
color: Colors.redAccent,
size: 23.0) : Icon(Icons.favorite_border,
color: Colors.redAccent,
size: 23.0)
),
/*Text(documents[index].data['Likes'].length.toString()),*/
],
),
),
Expanded(
child: IconButton(
onPressed: () {
navigateToDetail(documents[index],
documents[index].data["Userid"],);
},
icon: Icon(
Icons.chat_bubble_outline,
color: Colors.blue,
size: 23.0,
),
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.near_me,
color: Colors.blue,
size: 23.0,
),
),
),
],
),
],
),
),
),
);
});
}
}),
);
}
This is to get Posts :
Stream<QuerySnapshot> getPostsStream() {
return Firestore.instance.collection("Posts").orderBy(
"Creation Time", descending: true).snapshots();
}
Change this:
print(documents[index].data['Likes.$usersId']);
into this:
print(documents[index].data['Likes'][usersId]);
Hi so I was doing an app like uber but I got an error of this. I'm new in using flutter. Before this, I can run app this normally but suddenly I got this error this morning.
This is my code. Can someone help me?
this is the error
A build function returned null.
The offending widget is: StreamBuilder
To return an empty space that causes the building widget to fill available room, return "Container()". To return an empty space that takes as little room as possible, return "Container(width: 0.0, height: 0.0)".
import 'package:ezbin3/Aboutus.dart';
import 'package:ezbin3/SCREENS/home/map.dart';
import 'package:ezbin3/SCREENS/home/map2.dart';
import 'package:ezbin3/SERVICES/auth.dart';
import 'package:ezbin3/activity.dart';
import 'package:ezbin3/models/user.dart';
import 'package:ezbin3/profile.dart';
import 'package:ezbin3/settings.dart';
import 'package:flutter/material.dart';
import 'package:ezbin3/SERVICES/database.dart';
import 'package:provider/provider.dart';
import 'package:ezbin3/models/ezuser.dart';
class Home extends StatelessWidget {
final AuthService _auth = AuthService();
#override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
return StreamBuilder<EzuserData>(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
if (snapshot.hasData) {
EzuserData userData = snapshot.data;
return StreamProvider<List<Ezuser>>.value(
value: DatabaseService().userz,
child: Scaffold(
drawer: Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
decoration: BoxDecoration(
gradient: LinearGradient(colors: <Color>[
Colors.lightGreen,
Colors.green
])),
child: Container(
child: Column(
children: <Widget>[
Material(
borderRadius:
BorderRadius.all(Radius.circular(50.0)),
elevation: 10,
child: Padding(
padding: EdgeInsets.all(8.0),
child: Image.asset(
'image/ezbin2.png',
width: 80,
height: 80,
),
),
),
SizedBox(height: 10),
Text(
userData.name,
style: TextStyle(
color: Colors.white, fontSize: 20.0),
),
],
)),
),
//PROFILE PAGE
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.lightGreenAccent,
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfilePage())),
child: Container(
height: 50,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.person),
Padding(
padding:
const EdgeInsets.all(8.0),
child: Text('Profile',
style: TextStyle(
fontSize: 16.0))),
],
),
Icon(Icons.arrow_right)
],
),
)),
)),
//ACTIVITY PAGE
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.lightGreenAccent,
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ActivityPage())),
child: Container(
height: 50,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.description),
Padding(
padding:
const EdgeInsets.all(8.0),
child: Text('Activity',
style: TextStyle(
fontSize: 16.0))),
],
),
Icon(Icons.arrow_right)
],
),
)),
)),
//SETTING PAGE
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.lightGreenAccent,
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingPage())),
child: Container(
height: 50,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.settings),
Padding(
padding:
const EdgeInsets.all(8.0),
child: Text('Settings',
style: TextStyle(
fontSize: 16.0))),
],
),
Icon(Icons.arrow_right)
],
),
)),
)),
//ABOUT US PAGE
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.lightGreenAccent,
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AboutusPage())),
child: Container(
height: 50,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.info_outline),
Padding(
padding:
const EdgeInsets.all(8.0),
child: Text('About Us',
style: TextStyle(
fontSize: 16.0))),
],
),
Icon(Icons.arrow_right)
],
),
)),
)),
//LOG OUT
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.lightGreenAccent,
onTap: () async {
await _auth.signOut();
print('logout');
},
child: Container(
height: 50,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.lock),
Padding(
padding:
const EdgeInsets.all(8.0),
child: Text('Log Out',
style: TextStyle(
fontSize: 16.0))),
],
),
Icon(Icons.arrow_right)
],
),
)),
))
],
),
),
backgroundColor: Colors.green[50],
appBar: AppBar(
title: Text('EZBIN'),
backgroundColor: Colors.green[400],
elevation: 0.0,
actions: <Widget>[],
),
body: //HomeGoogle(),
MapSample(),
),
);
}
});
}
}
If anything happens please let me know. Thank you
Let's take a look at the error message
A build function returned null. The offending widget is: StreamBuilder
That means, that somewhere in your program a StreamBuilder (or its build method) is not returning a Widget, but null.
Now let's take a look at your code.
return StreamBuilder<EzuserData>(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
if (snapshot.hasData) {
EzuserData userData = snapshot.data;
return StreamProvider<List<Ezuser>>.value(
...
);
}
});
}
With the error and the simplified code in mind, where could you not return a Widget, but instead no value at all? Hint: What happens, if snapshot.hasData is not true?
body: StreamBuilder(
stream: Firestore.instance.collection('students').document(_userId).snapshots(),
builder: (context,snapshot) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left:20.0),
child: Align(
alignment: Alignment.centerRight,
child: CircleAvatar(
radius: 100,
backgroundColor: Colors.white,
child: ClipOval(
child: new SizedBox(
width: 180.0,
height: 180.0,
child: (_image!=null)?Image.file(
_image,
fit: BoxFit.fill,
):
Image.network(""),
),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 60.0),
child: IconButton(
icon: Icon(
Icons.camera,
size: 30.0,
),
onPressed: () {
getImage();
},
),
),
],
),
SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left:40.0),
child: Align(
alignment: Alignment.center,
child: Container(
child: Column(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text('Student Name',
style: TextStyle(
color: Colors.white, fontSize: 20.0)),
),
Align(
alignment: Alignment.center,
child: Text(snapshot.data['first_name'],
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
)),
),
],
),
),
),
),
i want to display student name from cloud firestore but it gives an error upon first loading but after hotreload the app works correctly.
here is my student id retrieving function
FirebaseAuth.instance.currentUser().then((user) {
_userId = user.uid;
});
i am using this id for retrieving a particular student details but it give error upon first loading the error are enter image description here
The database snap are enter image description here