Flutter里ListView控件(新手)

ListView控件使用

在ListView中嵌套,不能显示数据的几种

方式一:(网上找的办法,并无解决问题)bash

new Expanded(child:
              new ListView(
              //设置这个也没有做用
                shrinkWrap: true,
                children: _listView(),
              ),
            ),
复制代码

方式二:(Flexible 我是查看GridView嵌套这样设置,一样也没有效果)less

new Flexible(child:
                  new ListView(
                    children: _listView(),
                  ),
                flex: 1,
              ),
复制代码
new Flexible(child:
        new ListView(
            shrinkWrap: true,
            children: _listView(),
        ),
         flex: 1,
    ),

复制代码

错误日志ide

Performing hot reload...
I/flutter (13770): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (13770): The following assertion was thrown during performLayout():
I/flutter (13770): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter (13770): When a column is in a parent that does not provide a finite height constraint, for example if it is
I/flutter (13770): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (13770): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter (13770): space in the vertical direction.
I/flutter (13770): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter (13770): cannot simultaneously expand to fit its parent.
I/flutter (13770): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter (13770): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter (13770): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter (13770): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter (13770): constraints provided by the parent.
I/flutter (13770): The affected RenderFlex is:
I/flutter (13770):   RenderFlex#f6f9f relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (13770): The creator information is set to:
I/flutter (13770):   Column ← RepaintBoundary-[<0>] ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
I/flutter (13770):   AutomaticKeepAlive ← SliverList ← MediaQuery ← SliverPadding ← Viewport ← _ScrollableScope ←
I/flutter (13770):   IgnorePointer-[GlobalKey#f8b80] ← Semantics ← ⋯
I/flutter (13770): See also: https://flutter.io/layout/
I/flutter (13770): If this message did not help you determine the problem, consider using debugDumpRenderTree():

复制代码

问题

ListView嵌套ListView不能显示问题,使用以下方法:flex

在ListView中嵌套,使用Column(列)
处理方式一
        new Column(
            children: _listView(),
        ),
复制代码

总结处理方式一 ,能显示ui

查看错误信息,因而使用 Container 设置高度一样也能显示this

new Container(
            //设置高度,主要是设置 ListView 高度这样就指明了高度
            height: 100.0,
            child: new RaisedButton(onPressed: (){
              //print(" 点击了 Container RaisedButton ");
            },
              child: new ListView(
                children: _listView(),
              ),
              color: Colors.deepOrange,
            ),
          ),
复制代码

若是小伙伴,你有更好的处理方式请在评论留言,让你的举动丰富程序猿积累。spa

相关文章
相关标签/搜索