有问题的小部件是: FutureBuilder<Object> 构建函数绝不能返回 null

时间:2021-03-17 08:05:08

标签: firebase function flutter dart google-cloud-firestore

我在另一个页面上从 Firestore 中提取数据没有问题。当我在个人资料页面上编写相同的代码时,我收到了以下错误。

The following assertion was thrown building FutureBuilder<Object>(dirty, state: _FutureBuilderState<Object>#e4233)`:
A build function returned null.

The offending widget is: FutureBuilder<Object>
Build functions must never return null.

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)".

The relevant error-causing widget was: 
  FutureBuilder<Object> file:///C:/Flutter%20calismalari/rehber_uygulmasi_staj/lib/sayfalar/profil.dart:91:19
body: Column(children: [
          Padding(
            padding: const EdgeInsets.only(top: 18.0),
            child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [
              IconButton(
                  icon: Icon(FontAwesomeIcons.moon, size: 30),
                  onPressed: () {
                    setState(() {
                      mode = false;
                      print("tıklandı $mode");
                    });
                  })
            ]),
          ),
          Row(
            children: [
              Stack(
                children: [
                  FutureBuilder<Object>(
                      future: FirestoreServisi()
                          .kullaniciGetir(widget.profilSahibiId),
                      builder: (context, snapshot) {
                        if (!snapshot.hasData) {
                          return Center(child: CircularProgressIndicator());
                        }
                        return _profilResim(snapshot.data);
                      }

                      ),

                  Positioned(
                      child: Container(
                        child: CircleAvatar(
                          child: Icon(
                            Icons.edit,
                            color: Colors.yellow,
                            size: 15,
                          ),
                        ),
                      )),
                ],
              ),
              Column(
                children: [
                  FutureBuilder<Object>(
                      future: FirestoreServisi()
                          .kullaniciGetir(widget.profilSahibiId),
                      builder: (context, snapshot) {
                        if (!snapshot.hasData) {
                          return Center(child: CircularProgressIndicator());
                        }
                        return _profilUsername(snapshot.data);
                      }),

                  SizedBox(
                    height: 10,
                  ),
                  FutureBuilder<Object>(
                      future: FirestoreServisi()
                          .kullaniciGetir(widget.profilSahibiId),
                      builder: (context, snapshot) {
                        if (!snapshot.hasData) {
                          return Center(child: CircularProgressIndicator());
                        }
                        return _profilMail(snapshot.data);
                      }),
                  SizedBox(
                    height: 10,
                  ),
                  Container(
                      width: 200,
                      child: RaisedButton(
                        onPressed: () {},
                        color: Colors.yellow[200],
                        child: Text(
                          "Upgrade to PRO",
                          style: TextStyle(color: Colors.black),
                        ),
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(20)),
                      ))
                ],
              )
            ],
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: ListView.builder(
                  padding: const EdgeInsets.all(8),
                  itemCount: newModelList.length,
                  itemBuilder: (BuildContext context, int index) {
                    return InkWell(
                      onTap: () {},
                      child: Container(
                        height: 50,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(15),
                          color: Colors.grey,
                          boxShadow: [
                            BoxShadow(color: Colors.white, spreadRadius: 5),
                          ],
                        ),
                        child: InkWell(
                          onTap: () {},
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Icon(newModelList[index].iconData),
                              Text('${newModelList[index].entry}'),
                              Icon(Icons.arrow_forward_ios_outlined)
                            ],
                          ),
                        ),
                      ),
                    );
                  }),
            ),
          )
        ])

    );
  }

      _profilResim(Kullanici kullanici) {
    
        CircleAvatar(
          backgroundColor: Colors.grey[300],
          radius: 50.0,
          backgroundImage: NetworkImage(kullanici.fotoUrl),
        );
      }
    
      _profilUsername(Kullanici kullanici) => Text(
        kullanici.userName,
        style: TextStyle(
            color: Colors.white,  fontWeight: FontWeight.bold),
      );

      _profilMail(Kullanici kullanici) => Text(
        kullanici.email,
        style: TextStyle(
            color: Colors.white,  fontWeight: FontWeight.bold),
      );

2 个答案:

答案 0 :(得分:1)

您忘记在 _profilResim() 函数中返回小部件:

Widget _profilResim(Kullanici kullanici) {
  return CircleAvatar(
    backgroundColor: Colors.grey[300],
    radius: 50.0,
    backgroundImage: NetworkImage(kullanici.fotoUrl),
  );
}

答案 1 :(得分:0)

我认为这是因为 Network Image

_profilResim(Kullanici kullanici) {

    CircleAvatar(
      backgroundColor: Colors.grey[300],
      radius: 50.0,
      backgroundImage: NetworkImage(kullanici.fotoUrl != null ? kullanici.fotoUrl : ''),
    );
  }