Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(颤振)带有Streambuilder的ontap ListView(返回listTile())导致继承数据为空?_Listview_Flutter_Google Cloud Firestore_Stream Builder_Materialpageroute - Fatal编程技术网

(颤振)带有Streambuilder的ontap ListView(返回listTile())导致继承数据为空?

(颤振)带有Streambuilder的ontap ListView(返回listTile())导致继承数据为空?,listview,flutter,google-cloud-firestore,stream-builder,materialpageroute,Listview,Flutter,Google Cloud Firestore,Stream Builder,Materialpageroute,您好,我正在尝试使用Streambuilder创建简单的实时数据库,同时返回一个Listview.builder,其中有一个ListTile。我希望列表能够移动到其他省道。但是,当我试图传递项目时,它会变成null,但当我试图打印它时,它会在终端中打印 class ListItemsDisplay extends StatefulWidget { @override State<StatefulWidget> createState() {

您好,我正在尝试使用Streambuilder创建简单的实时数据库,同时返回一个Listview.builder,其中有一个ListTile。我希望列表能够移动到其他省道。但是,当我试图传递项目时,它会变成null,但当我试图打印它时,它会在终端中打印

 class ListItemsDisplay extends StatefulWidget {
      @override
      State<StatefulWidget> createState() {
        return _ListItemsDisplay();
      }
    }

    class _ListItemsDisplay extends State<ListItemsDisplay> {
      @override
      Widget build(BuildContext context) {
        return new StreamBuilder(
            stream: Firestore.instance.collection("posts").snapshots(),
            builder: (context, snapshot) {
              if (!snapshot.hasData) {
                return Center(
                  child: Text("Loading.."),
                );
              } else {
                return ListView.builder(
                    itemCount: snapshot.data.documents.length,
                    itemBuilder: (context, index)`enter code here` {
                      if (snapshot.data.documents[index]['title'] != null &&
                          snapshot.data.documents[index]['title'] != "" &&
                          snapshot.data.documents[index]['title'] != " ") {
                        print(
                            "MY ID: " + snapshot.data.documents[index].documentID);
                        return ListTile(
                            title: Text(snapshot.data.documents[index]['title']),
                            onTap: () {
                              if (snapshot.data.documents[index]['title'] != 

    null) {**//AS YOU CAN SEE HERE IM TRYING TO PASS the document id in DISPLAYITEM() CLASS**
    print("MY ITEM ID ""TAPPED"" IF NOT NULL: "+snapshot.data.documents[index].documentID);
                                Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) => DisplayItem(snapshot.data.documents[index].documentID)));
                              } else {
                                print("MY ITEM ID ""TAPPED"" IF NULL: "+snapshot.data.documents[index].documentID);
                              }
                            });
                      } else {
                        return ListTile(
                          title: Text("Missing title [REPORT TO ADMIN]"),
                        );
                      }
                    });
              }
            });
      }
    }
当我单击此(显示项)时file:///D:/Programming/Flutter_Projects/flutter_study/lib/main.dart:64:59)

我重定向到这里: 生成器:(上下文)=>DisplayItem(snapshot.data.documents[index.documentID))


点击列表时,您得到的值是多少
snapshot.data.documents[index].documentID
try
Text(\u myId)
。是否出现异常?确定,表示
id
不为空。可能的
value.data['title'].toString()
则为空。通过打印
value.data['title'].toString()
来检查值。您知道如何使用
ConnectionState
?在
连接中显示
文本(snapshot.data[“title”]
。激活
,您就可以开始了。没问题…..点击列表时您得到了什么值?
snapshot.data.documents[index]。documentID
尝试
文本(\u myId)
。是否出现异常?好的,意思是
id
不为空。可能的
值。数据['title'].toString()
则为空。通过打印
value.data['title'].toString()
来检查值。您知道如何使用
ConnectionState
吗?在
连接中显示
文本(快照.data[“title”]
。处于活动状态
,您就可以开始了。没问题。。。。。
class DisplayItem extends StatelessWidget {
  final String _myId;
  DisplayItem(this._myId);
  String getTitle(String myId) {
    if(myId.isNotEmpty && myId!=null) {
      Firestore.instance.collection("posts").document(myId).get().then((value) {
        if (value.data['title'].toString() != null &&
            value.data['title'].toString() != "" &&
            value.data['title'].toString() != " ")
          return value.data['title'].toString();
        else
          return "NONE FOUND";
      });
    }
    else
      return "HELLO";
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
        appBar: AppBar(
        title: Text("TITLE"),
    ),
    body: Column(
    children: <Widget>[
      Text(getTitle(_myId)),
    ],
    ),
    ),
    );
    }
  }
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building DisplayItem(dirty):
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 298 pos 10: 'data != null'

The relevant error-causing widget was: 
  DisplayItem file:///D:/Programming/Flutter_Projects/flutter_study/lib/main.dart:64:59
When the exception was thrown, this was the stack: 
#2      new Text (package:flutter/src/widgets/text.dart:298:10)
#3      DisplayItem.build (package:flutterstudy/Display.dart:31:7)
#4      StatelessElement.build (package:flutter/src/widgets/framework.dart:4576:28)
#5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
#6      Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

HERE IS THE ID IM TRYING TO PASS
I/flutter (11339): MY NOT NULL ID: sc94LjZJz57t947YgTlp
HERE's WHAT HAPPENS:
as soon as I ran, I added a print method that will print document ID of items.
I/flutter (13386): MY ID: sc94LjZJz57t947YgTlp
I/flutter (13386): MY ID: xqbkvhVveYhr3YvgSGuE

Now I clicked any of the Item

IT Shows the **ERROR ON TERMINAL** then it displays the last method I added in onTap, which print method:
I/flutter (13386): MY ITEM ID TAPPED IF NOT NULL: sc94LjZJz57t947YgTlp