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
Flutter SingleChildScrollView颤振中的Streambuilder错误_Flutter - Fatal编程技术网

Flutter SingleChildScrollView颤振中的Streambuilder错误

Flutter SingleChildScrollView颤振中的Streambuilder错误,flutter,Flutter,这是封装在脚手架主体内SingleChildScrollView下的streambuilder。将streambuilder置于SingleChildScrollView下后,滚动视图不工作。StreamBuilder通过云firestore从firebase获取数据 body: Container( child: SingleChildScrollView( child: Column( mainAxisAli

这是封装在脚手架主体内SingleChildScrollView下的streambuilder。将streambuilder置于SingleChildScrollView下后,滚动视图不工作。StreamBuilder通过云firestore从firebase获取数据

body: Container(
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                    Expanded(
                    child: StreamBuilder<QuerySnapshot>(
                      stream: Firestore.instance
                          .collection(
                              'blogsDatabase/${widget.blogUIDInFirebase}/comments')
                          .snapshots(),
                      builder: (context, snapshot) {
                        if (!snapshot.hasData) {
                          return Center(child: CircularProgressIndicator());
                        }
                        final _commentsFetched = snapshot.data.documents;
                        List<CommentBubble> _commentBubbleWidget = [];
    
                        for (var comment in _commentsFetched) {
                          _commentBubbleWidget.add(
                            CommentBubble(
                              name: comment.data['name'],
                              comment: comment.data['comment'],
                            ),
                          );
                        }
                        return Expanded(
                          child: ListView(
                            children: _commentBubbleWidget
                          ),
                        );
                      },
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.all(10),
                    child: Material(
                      shadowColor: Colors.orange,
                      child: TextField(
                        onChanged: (value) {
                          readerAddComment = value;
                        },
                        keyboardType: TextInputType.emailAddress,
                        decoration:
                            kRegDetailFieldDeco.copyWith(hintText: 'Add comment'),
                      ),
                    ),
                  ),
                  FlatButton(
                      onPressed: () {
                        if (_nameReader != null &&
                            widget.readerEmail != null &&
                            readerAddComment != null) {
                          Firestore.instance
                              .collection(
                                  'blogsDatabase/${widget.blogUIDInFirebase}/comments')
                              .document()
                              .setData(
                            {
                              'name': _nameReader,
                              'email': widget.readerEmail,
                              'comment': readerAddComment,
                            },
                          );
                        }
                      },
                      child: Text('Add comment')),
                ],
              ),
            ),
          ),
控制台中显示错误

RenderBox was not laid out: RenderRepaintBoundary#dd879 relayoutBoundary=up1 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1694 pos 12: 'hasSize'

它之所以发生,是因为你的小部件结构是由哪个错误引起的,就像

-Container
  -SingleChildScrollView  
    -Expanded
       -Column
         -Expanded
             -Expanded
               -ListView

现在看到你得到的这个错误,它说这是关于大小的错误,将你的列包装在其他一些小部件中而不是展开

似乎你需要空间将ListView放在列()中。 移除扩展的小部件,并将其替换为容器。 例如:

容器( 身高:100, 子:ListView( 儿童:_commentBubbleWidget ),)

但是,我不建议您使用上述解决方案。这对UI来说太糟糕了(只是我的意见)。因为,在列中使用ListView。通过使用这种方法,您必须确定ListView的高度。别忘了,手机的尺寸各不相同

最好将ListView分开,并将文本字段放在BottomNavigationBar中。 这是我的:

Scaffold(
  appBar: AppBar(
    title: textCustom(
        'Review ${widget.destination}', Colors.black87, 20, 'Hind'),
    leading: IconButton(
        icon: Icon(
          Icons.arrow_back_ios,
        ),
        onPressed: () {
          Navigator.pop(context);
        }),
    iconTheme: IconThemeData(color: Colors.black87, size: 10),
    backgroundColor: Colors.transparent,
    elevation: 0.0,
  ),
  body: Padding(
    padding: const EdgeInsets.all(8.0),
    child: StreamBuilder<QuerySnapshot>(
        stream: kategori
            .document(widget.kategori)
            .collection(widget.subKategori)
            .document(widget.docId)
            .collection("review")
            .orderBy("timeStamp", descending: true)
            .snapshots(),
        builder:
            (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (snapshot.hasError) return new Text('${snapshot.error}');
          if (snapshot.data == null)
            return Center(
                child: textCustom(
                    'Loading...', Colors.black87, 14, 'Montserrat'));

          final review= snapshot.data.documents;
          return snapshot.data.documents.isNotEmpty
              ? ListView.builder(
                  itemCount: review.length,
                  itemBuilder: (context, index) {
                    return Comment(
                      name: review[index]['name'],
                      profilePhoto: review[index]['foto'],
                      comments: review[index]['review'],
                      date: (review[index]['timeStamp'] != null)
                          ? DateFormat.yMMMd().format(DateTime.parse(
                              review[index]['timeStamp']
                                  .toDate()
                                  .toString(),
                            ))
                          : '',
                    );
                  })
              : Center(child: Text('Empty'));
        }),
  ),
  bottomNavigationBar: Padding(
    padding: MediaQuery.of(context).viewInsets,
    child: BottomAppBar(
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 8.0),
        child: Row(
          children: <Widget>[
            Expanded(
                child: TextField(
              controller: textMessageController,
              onChanged: (text) {
                input = text;
                setState(() {
                  enableButton = text.isNotEmpty;
                });
              },
              textCapitalization: TextCapitalization.sentences,
              maxLines: null,
              style: TextStyle(
                  color: Colors.black87,
                  fontSize: 16,
                  fontFamily: 'Montserrat'),
              decoration: InputDecoration(
                enabledBorder: UnderlineInputBorder(
                  borderSide: new BorderSide(color: Colors.white),
                  borderRadius: new BorderRadius.circular(8.0),
                ),
                focusedBorder: OutlineInputBorder(
                  borderSide: new BorderSide(color: Colors.white),
                  borderRadius: new BorderRadius.circular(8.0),
                ),
                contentPadding:
                    EdgeInsets.only(left: 16.0, bottom: 16.0, top: 16.0),
                hintText: 'Write some review',
              ),
            )),
            SizedBox(
              width: 8.0,
            ),
            enableButton
                ? IconButton(
                    onPressed: handleSendMessage,
                    icon: Icon(
                      Icons.send,
                      color: Color(0xFFDB5C48),
                    ))
                : IconButton(
                    onPressed: () {},
                    icon: Icon(
                      Icons.send,
                      color: Colors.grey,
                    ))
          ],
        ),
      ),
    ),
  ),
);
脚手架(
appBar:appBar(
标题:文本自定义(
'Review${widget.destination}',Colors.black87,20,'Hind'),
领先:IconButton(
图标:图标(
Icons.arrow\u back\u ios,
),
已按下:(){
Navigator.pop(上下文);
}),
iconTheme:IconThemeData(颜色:Colors.black87,大小:10),
背景颜色:颜色。透明,
标高:0.0,
),
主体:填充物(
填充:常数边集全部(8.0),
孩子:StreamBuilder(
溪流:kategori
.document(widget.kategori)
.collection(widget.subKategori)
.document(widget.docId)
.收集(“审查”)
.orderBy(“时间戳”,降序:true)
.snapshots(),
建设者:
(BuildContext上下文,异步快照){
if(snapshot.hasError)返回新文本(“${snapshot.error}”);
如果(snapshot.data==null)
返回中心(
孩子:textCustom(
“装载…”,Colors.black87,14,“蒙特塞拉特”);
最终审查=快照.data.documents;
返回snapshot.data.documents.isNotEmpty
?ListView.builder(
itemCount:review.length,
itemBuilder:(上下文,索引){
回复评论(
名称:审阅[索引]['name'],
简介照片:回顾[索引]['foto'],
评论:评论[索引][“评论”],
日期:(查看[索引]['timeStamp']!=null)
?DateFormat.yMMMd().format(DateTime.parse(
查看[索引][“时间戳”]
.toDate()
.toString(),
))
: '',
);
})
:居中(子项:文本('Empty');
}),
),
底部导航栏:填充(
填充:MediaQuery.of(context).viewInsets,
子项:BottomAppBar(
孩子:填充(
填充:常量边集。对称(水平:8.0),
孩子:排(
儿童:[
扩大(
孩子:TextField(
控制器:textMessageController,
一旦更改:(文本){
输入=文本;
设置状态(){
enableButton=text.isNotEmpty;
});
},
text大写:text大写。句子,
maxLines:null,
样式:TextStyle(
颜色:颜色。黑色87,
尺寸:16,
fontFamily:“蒙特塞拉特”),
装饰:输入装饰(
enabledBorder:UnderlineInputBorder(
borderSide:新的borderSide(颜色:Colors.white),
边界半径:新边界半径。圆形(8.0),
),
聚焦顺序:大纲输入边框(
borderSide:新的borderSide(颜色:Colors.white),
边界半径:新边界半径。圆形(8.0),
),
内容填充:
仅限边集(左:16.0,下:16.0,上:16.0),
hintText:“写一些评论”,
),
)),
大小盒子(
宽度:8.0,
),
启用按钮
?图标按钮(
onPressed:handleSendMessage,
图标:图标(
Icons.send,
颜色:颜色(0xFFDB5C48),
))
:图标按钮(
按下:(){},
图标:图标(
Icons.send,
颜色:颜色。灰色,
))
],
),
),
),
),
);
Scaffold(
  appBar: AppBar(
    title: textCustom(
        'Review ${widget.destination}', Colors.black87, 20, 'Hind'),
    leading: IconButton(
        icon: Icon(
          Icons.arrow_back_ios,
        ),
        onPressed: () {
          Navigator.pop(context);
        }),
    iconTheme: IconThemeData(color: Colors.black87, size: 10),
    backgroundColor: Colors.transparent,
    elevation: 0.0,
  ),
  body: Padding(
    padding: const EdgeInsets.all(8.0),
    child: StreamBuilder<QuerySnapshot>(
        stream: kategori
            .document(widget.kategori)
            .collection(widget.subKategori)
            .document(widget.docId)
            .collection("review")
            .orderBy("timeStamp", descending: true)
            .snapshots(),
        builder:
            (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (snapshot.hasError) return new Text('${snapshot.error}');
          if (snapshot.data == null)
            return Center(
                child: textCustom(
                    'Loading...', Colors.black87, 14, 'Montserrat'));

          final review= snapshot.data.documents;
          return snapshot.data.documents.isNotEmpty
              ? ListView.builder(
                  itemCount: review.length,
                  itemBuilder: (context, index) {
                    return Comment(
                      name: review[index]['name'],
                      profilePhoto: review[index]['foto'],
                      comments: review[index]['review'],
                      date: (review[index]['timeStamp'] != null)
                          ? DateFormat.yMMMd().format(DateTime.parse(
                              review[index]['timeStamp']
                                  .toDate()
                                  .toString(),
                            ))
                          : '',
                    );
                  })
              : Center(child: Text('Empty'));
        }),
  ),
  bottomNavigationBar: Padding(
    padding: MediaQuery.of(context).viewInsets,
    child: BottomAppBar(
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 8.0),
        child: Row(
          children: <Widget>[
            Expanded(
                child: TextField(
              controller: textMessageController,
              onChanged: (text) {
                input = text;
                setState(() {
                  enableButton = text.isNotEmpty;
                });
              },
              textCapitalization: TextCapitalization.sentences,
              maxLines: null,
              style: TextStyle(
                  color: Colors.black87,
                  fontSize: 16,
                  fontFamily: 'Montserrat'),
              decoration: InputDecoration(
                enabledBorder: UnderlineInputBorder(
                  borderSide: new BorderSide(color: Colors.white),
                  borderRadius: new BorderRadius.circular(8.0),
                ),
                focusedBorder: OutlineInputBorder(
                  borderSide: new BorderSide(color: Colors.white),
                  borderRadius: new BorderRadius.circular(8.0),
                ),
                contentPadding:
                    EdgeInsets.only(left: 16.0, bottom: 16.0, top: 16.0),
                hintText: 'Write some review',
              ),
            )),
            SizedBox(
              width: 8.0,
            ),
            enableButton
                ? IconButton(
                    onPressed: handleSendMessage,
                    icon: Icon(
                      Icons.send,
                      color: Color(0xFFDB5C48),
                    ))
                : IconButton(
                    onPressed: () {},
                    icon: Icon(
                      Icons.send,
                      color: Colors.grey,
                    ))
          ],
        ),
      ),
    ),
  ),
);