嗨,我当时正在做类似uber的应用,但我遇到了一个错误。我是第一次使用颤振。在此之前,我可以正常运行此应用程序,但今天早晨突然出现此错误。 这是我的代码。有人可以帮我吗?
这是错误
一个构建函数返回null。 有问题的小部件是:StreamBuilder 要返回使建筑物小部件填充可用空间的空白区域,请返回“ Container()”。要返回占用尽可能少空间的空白空间,请返回“ 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(),
),
);
}
});
}
}
如果发生任何事情,请告诉我。谢谢
答案 0 :(得分:0)
让我们看看错误消息
A build function returned null. The offending widget is: StreamBuilder
这意味着,在程序中的某个地方,StreamBuilder(或其构建方法)不是返回Widget,而是返回null
。
现在,让我们看一下您的代码。
return StreamBuilder<EzuserData>(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
if (snapshot.hasData) {
EzuserData userData = snapshot.data;
return StreamProvider<List<Ezuser>>.value(
...
);
}
});
}
考虑到错误和简化的代码,您在哪里不能返回Widget,而根本不返回值?提示:如果snapshot.hasData
不正确怎么办?