简体   繁体   English

一个构建函数返回 null ,相关的导致错误的小部件是:StreamBuilder<EzuserData>

[英]A build function returned null ,The relevant error-causing widget was : StreamBuilder<EzuserData>

Hi so I was doing an app like uber but I got an error of this.嗨,我正在做一个像 uber 这样的应用程序,但我遇到了这个错误。 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.构建函数返回 null。 The offending widget is: StreamBuilder To return an empty space that causes the building widget to fill available room, return "Container()".有问题的小部件是: StreamBuilder要返回导致建筑小部件填满可用空间的空白空间,请返回“Container()”。 To return an empty space that takes as little room as possible, return "Container(width: 0.0, height: 0.0)".要返回占用尽可能少空间的空白空间,请返回“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 .这意味着,在您的程序中的某个地方, StreamBuilder(或其构建方法)不返回 Widget,而是返回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?考虑到错误和简化的代码,您在哪里可以不返回 Widget,而是根本没有值? Hint: What happens, if snapshot.hasData is not true?提示:如果snapshot.hasData不正确会发生什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 相关的导致错误的小部件是 StreamBuilder <querysnapshot<object?> &gt; </querysnapshot<object?> - The relevant error-causing widget was StreamBuilder<QuerySnapshot<Object?>> 找不到 MediaQuery 小部件祖先。相关的导致错误的小部件是 FutureBuilder<FirebaseApp> - No MediaQuery widget ancestor found.The relevant error-causing widget was FutureBuilder<FirebaseApp> “String”类型不是“index”类型“int”的子类型相关的导致错误的小部件是 FutureBuilder<dynamic></dynamic> - type 'String' is not a subtype of type 'int' of 'index' The relevant error-causing widget was FutureBuilder<dynamic> Flutter StreamBuilder 返回 null - Flutter StreamBuilder returned null Flutter 错误“构建 function 返回 null” - Flutter error "A build function returned null" “构建 function 返回 null。有问题的小部件是:信息构建函数不得返回 null。返回一个空白空间” - "A build function returned null. The offending widget is: info Build functions must never return null. To return an empty space" 带有 flutter_firebase 的 StreamBuilder 在第二个小部件构建时具有 null 值(图像消失) - StreamBuilder with flutter_firebase has null value on second widget build (image disappears) Flutter Future:构建函数返回null - Flutter Future:A build function returned null 构建 function 返回 null。 Flutter Firebase - A build function returned null. Flutter Firebase Streambuilder 空错误。 变量返回 Null - Streambuilder Null Error. Variable returning Null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM