Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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 项目的颤振列表视图作为分隔器,带有项目大小问题的列表视图_Flutter - Fatal编程技术网

Flutter 项目的颤振列表视图作为分隔器,带有项目大小问题的列表视图

Flutter 项目的颤振列表视图作为分隔器,带有项目大小问题的列表视图,flutter,Flutter,我有一个工作页面,它是使用listview.builder的消息动态listview。itembuilder调用创建卡的小部件。我试图做的是将第一个列表更改为一个分隔符,该分隔符将是一个日期,然后在该日期前调用一个项目列表。所有的数据调用和列表都在创建中,但不断出现hasSize不是真的错误,并且看不出大小在哪里是个问题,我只是使用了与工作时相同的布局 不确定要显示哪些代码以获得帮助,所以如果您有想法,请告诉我您可能需要查看哪些代码 这是在更改之前工作的开始: var _children = &

我有一个工作页面,它是使用listview.builder的消息动态listview。itembuilder调用创建卡的小部件。我试图做的是将第一个列表更改为一个分隔符,该分隔符将是一个日期,然后在该日期前调用一个项目列表。所有的数据调用和列表都在创建中,但不断出现hasSize不是真的错误,并且看不出大小在哪里是个问题,我只是使用了与工作时相同的布局

不确定要显示哪些代码以获得帮助,所以如果您有想法,请告诉我您可能需要查看哪些代码

这是在更改之前工作的开始:

var _children = <Widget>[

  new Expanded(
    child: new RefreshIndicator(
      child: new ListView.builder(
        itemBuilder: _divBuilder,
        itemCount: listcount,
      ),
      onRefresh: _onRefresh,
    ),
  ),
  new Stack(
    alignment: Alignment.centerRight,
    children: <Widget>[
      new TextField(
        decoration: const InputDecoration(
          hintText: 'Chat Reply',
          labelText: 'Chat Reply:',
        ),
        autofocus: false,
        focusNode: _focusnode,
        maxLines: 2,
        controller: _newreplycontroller,
        keyboardType: TextInputType.url,
      ),
      new IconButton(
        icon: new Icon(Icons.send),
        onPressed: _sendReply,
        alignment: Alignment.centerRight,
      )
    ],
  ),
];
return new Scaffold(
  appBar: new AppBar(
    title: mytitle,
    actions: getAppBarActions(context),
  ),
  body: new Column(
    mainAxisSize: MainAxisSize.max,
    children: _children,
  ),
);
var\u子项=[
新扩展(
子项:新的刷新指示器(
子项:新建ListView.builder(
itemBuilder:\u divBuilder,
itemCount:listcount,
),
onRefresh:\u onRefresh,
),
),
新堆栈(
对齐:alignment.centerRight,
儿童:[
新文本字段(
装饰:常量输入装饰(
hintText:“聊天回复”,
labelText:'聊天回复:',
),
自动对焦:错误,
focusNode:_focusNode,
maxLines:2,
控制器:\u newreplycontroller,
键盘类型:TextInputType.url,
),
新图标按钮(
图标:新图标(Icons.send),
按下按钮:\ u sendReply,
对齐:alignment.centerRight,
)
],
),
];
归还新脚手架(
appBar:新的appBar(
标题:我的标题,
操作:getAppBarActions(上下文),
),
正文:新栏目(
mainAxisSize:mainAxisSize.max,
儿童:_儿童,
),
);
现在我有两个正在使用的小部件

    class MyChatWidget extends StatefulWidget {
  MyChatWidget({Key key, this.datediv, this.msgkey}) : super(key: key);

  final DateTime datediv;
  final String msgkey;

  @override
  _MyChatWidgetState createState() => new _MyChatWidgetState();
}

class _MyChatWidgetState extends State<MyChatWidget> {
  List messagelist;
  int messagecount = 0;
  var jsonCodec = const JsonCodec();

  _getMessages() async {
    var _url = 'http://$baseurl/csapi/messages/getbydate';
    DateChatMessage dcm = new DateChatMessage(widget.msgkey, widget.datediv.toString());
    var json = jsonCodec.encode(dcm);
    var http = createHttpClient();
    var response = await http.post(_url, headers: getAuthHeader(), body: json);

    var messages = await jsonCodec.decode(response.body);

    if (mounted) {
      setState(() {
        messagelist = messages.toList();
        messagecount = messagelist.length;
        //replysub = 'Re: ' + chatlist[0]['sub'];
      });
    }
  }

  @override
  void initState() {
    super.initState();
    //controller = new TabController(length: 4, vsync: this);
    _getMessages();
  }

  @override
  Widget build(BuildContext context) {
    var _children = <Widget>[
      new Divider(height: 5.0,color: Colors.red,),
      new Expanded(
        child: new ListView.builder(
          itemBuilder: _itemBuilder,
          itemCount: messagecount,
        ),
      ),

    ];


    return new Column(
        mainAxisSize: MainAxisSize.min,
        children: _children,
      );
  }

  Widget _itemBuilder(BuildContext context, int index) {
    ChatMessage mychat = getChat(index);
    return new ChatWidget(
      mychat: mychat,
    );
  }

  ChatMessage getChat(int index) {
    //prefs.setInt('pid', myReferralList[index]['pid']);
    return new ChatMessage(
      messagelist[index]['msgkey'],
      messagelist[index]['referralname'],
      messagelist[index]['sub'],
      messagelist[index]['oid'],
      messagelist[index]['oname'],
      messagelist[index]['pid'],
      messagelist[index]['pname'],
      messagelist[index]['sender'],
      messagelist[index]['sendname'],
      messagelist[index]['receiver'],
      messagelist[index]['receivename'],
      messagelist[index]['message'],
      messagelist[index]['submitdate'],
      messagelist[index]['pgrpid'],
      messagelist[index]['prid'],
      messagelist[index]['fcmtoken'],
    );
  }
}


class ChatWidget extends StatefulWidget {
  ChatWidget({Key key, this.mychat}) : super(key: key);

  final ChatMessage mychat;

  @override
  _ChatWidgetState createState() => new _ChatWidgetState();
}

class _ChatWidgetState extends State<ChatWidget> {
  @override
  Widget build(BuildContext context) {
    DateTime submitdate = DateTime.parse(widget.mychat.submitdate).toLocal();

    return new Card(
      child: new Container(
        width: 150.0,
        padding: new EdgeInsets.all(10.0),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            new Row(
              children: <Widget>[
                new Text(
                  widget.mychat.sendname,
                  style: new TextStyle(
                      fontSize: 15.0, fontWeight: FontWeight.bold),
                ),
                new Text(' @ '),
                new Text(new DateFormat.yMd().add_Hm().format(submitdate)),
                //new Text(submitdate.toLocal().toString())
              ],
            ),

            //new Text(widget.mychat.receivename,style: new TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),),
            //new Text(new DateFormat.yMd().add_Hm().format(submitdate)),
            new Text('${widget.mychat.message}'),
          ],
        ),
      ),
    );
    /*return new ListTile(
      leading: new CircleAvatar(child: new Text(widget.mychat.oname[0])),
      title: new Text(widget.mychat.referralname),
      subtitle: new Text(new DateFormat.yMd().add_Hm().format(submitdate)),
      trailing: new Text(widget.mychat.sendname),
      onTap: _onTap,
    );*/
  }



void _onTap() {
    Route route = new MaterialPageRoute(
      settings: new RouteSettings(name: "/chats/chatconvodetil"),
      builder: (BuildContext context) =>
      new ChatConvoDetail(mychat: widget.mychat),
    );
    Navigator.of(context).push(route);
  }
}
MyChatWidget类扩展了StatefulWidget{ MyChatWidget({Key-Key,this.datediv,this.msgkey}):超级(Key:Key); 最终日期时间日期div; 最终字符串msgkey; @凌驾 _MyChatWidgetState createState()=>新建; } 类\u MyChatWidgetState扩展状态{ 列表消息列表; int messagecount=0; var jsonCodec=const jsonCodec(); _getMessages()异步{ var_url='http://$baseurl/csapi/messages/getbydate'; DateChatMessage dcm=新的DateChatMessage(widget.msgkey,widget.datediv.toString()); var json=jsoncode.encode(dcm); var http=createHttpClient(); var response=wait http.post(_url,headers:getAuthHeader(),body:json); var messages=wait jsoncode.decode(response.body); 如果(已安装){ 设置状态(){ messagelist=messages.toList(); messagecount=messagelist.length; //replysub='Re:'+chatlist[0]['sub']; }); } } @凌驾 void initState(){ super.initState(); //控制器=新的TabController(长度:4,vsync:this); _getMessages(); } @凌驾 小部件构建(构建上下文){ 变量_子项=[ 新分隔器(高度:5.0,颜色:Colors.red,), 新扩展( 子项:新建ListView.builder( itemBuilder:\u itemBuilder, itemCount:messagecount, ), ), ]; 返回新列( mainAxisSize:mainAxisSize.min, 儿童:_儿童, ); } Widget\u itemBuilder(构建上下文,int索引){ ChatMessage mychat=getChat(索引); 返回新聊天窗口小部件( mychat:mychat, ); } ChatMessage getChat(int索引){ //prefs.setInt('pid',myReferralList[index]['pid']); 返回新聊天室消息( 消息列表[索引]['msgkey'], messagelist[索引]['referralname'], 消息列表[索引]['sub'], messagelist[索引]['oid'], 消息列表[索引]['oname'], messagelist[索引]['pid'], messagelist[索引]['pname'], messagelist[索引][“发件人”], messagelist[索引]['sendname'], messagelist[索引]['receiver'], messagelist[索引]['receivename'], messagelist[索引]['message'], messagelist[索引]['submitdate'], messagelist[索引]['pgrpid'], 消息列表[索引]['prid'], 消息列表[索引]['fcmtoken'], ); } } 类ChatWidget扩展StatefulWidget{ ChatWidget({Key,this.mychat}):super(Key:Key); 最后聊天信息mychat; @凌驾 _ChatWidgetState createState()=>新建; } 类ChatWidgetState扩展了状态{ @凌驾 小部件构建(构建上下文){ DateTime submitdate=DateTime.parse(widget.mychat.submitdate.toLocal(); 归还新卡( 子容器:新容器( 宽度:150.0, 填充:新边缘设置。全部(10.0), 子:新列( mainAxisAlignment:mainAxisAlignment.start, crossAxisAlignment:crossAxisAlignment.start, mainAxisSize:mainAxisSize.min, 儿童:[ 新行( 儿童:[ 新文本( widget.mychat.sendname, 样式:新文本样式( fontSize:15.0,fontWeight:fontWeight.bold), ), 新文本(“@”), 新文本(new DateFormat.yMd().add_Hm().format(submitdate)), //新文本(submitdate.toLocal().toString()) ], ), //新文本(widget.mychat.receivename,样式:新文本样式(fontSize:15.0,fontWeight:fontWeight.bold)), //新文本(new DateFormat.yMd().add_Hm().format(submitdate)), 新文本(“${widget.mychat.message}”), ], ), ), ); /*返回新的ListTile( 前导:新CircleAvatar(子:新文本(widget.mychat.oname[0]), 标题:新文本(widget.mychat.referralname), 字幕:新文本(new DateFormat.yMd().add_Hm().format(submitdate)), 尾随:新文本(widget.mychat.sendname), onTap:_onTap, );*/ } void_onTap(){ 路线=新材料路线( 设置:新路由设置(名称:“/chats/chatcolvedetil”), 生成器:(BuildContext上下文)=> 新详细信息(m)
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY 

╞═════════════════════════════════════════════════════════
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
When a column is in a parent that does not provide a finite height constraint, for example if it is
in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
space in the vertical direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
cannot simultaneously expand to fit its parent.
Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
themselves to less than the infinite remaining space they would otherwise be forced to take, and
then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
constraints provided by the parent.
The affected RenderFlex is:
RenderFlex#d88d8 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT
The creator information is set to:
Column ← MyChatWidget ← RepaintBoundary-[<0>] ← NotificationListener<KeepAliveNotification> ←
KeepAlive ← AutomaticKeepAlive ← SliverList ← ShrinkWrappingViewport ← _ScrollableScope ←
IgnorePointer-[GlobalKey#ac8f6] ← Listener ← _GestureSemantics ← ⋯
See also: https://flutter.io/layout/
https://flutter.io/debugging/#rendering-layer
http://docs.flutter.io/flutter/rendering/debugDumpRenderTree.html
If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
https://github.com/flutter/flutter/issues/new

When the exception was thrown, this was the stack:

The following RenderObject was being processed when the exception was fired:
RenderFlex#d88d8 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT
creator: Column ← MyChatWidget ← RepaintBoundary-[<0>] ←
NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← SliverList ←
ShrinkWrappingViewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#ac8f6] ← Listener ←
_GestureSemantics ← ⋯
size: MISSING
direction: vertical
mainAxisAlignment: start
mainAxisSize: min
crossAxisAlignment: center
verticalDirection: down
RenderConstrainedBox#1d682 relayoutBoundary=up9 NEEDS-PAINT
RenderPositionedBox#d9c42 relayoutBoundary=up10 NEEDS-PAINT
RenderPadding#c357c relayoutBoundary=up11 NEEDS-PAINT
RenderConstrainedBox#3ad51 relayoutBoundary=up12 NEEDS-PAINT
RenderDecoratedBox#e68e0 relayoutBoundary=up13 NEEDS-PAINT
RenderSemanticsGestureHandler#83b48 NEEDS-LAYOUT NEEDS-PAINT
RenderPointerListener#9b129 NEEDS-LAYOUT NEEDS-PAINT
RenderIgnorePointer#aa9c2 NEEDS-LAYOUT NEEDS-PAINT
RenderShrinkWrappingViewport#f658c NEEDS-LAYOUT NEEDS-PAINT
RenderSliverList#7b88e NEEDS-LAYOUT NEEDS-PAINT
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: 'package:flutter/src/rendering/box.dart': Failed assertion: line 1433 pos 12: 'hasSize': is not true.
Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 455 pos 12: 'child.hasSize': is not true.