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

相關文章
相關標籤/搜索