flutter -------- ListView的使用

學習了Flutter,來分享一下學習的一些經常使用的知識,先來講說ListViewhtml

 

案例效果:java

 

 

 

ListView是一個相似列的widget,它的內容對於其渲染框太長時會自動提供滾動。算法

ListView 摘要:
用於組織盒子中列表的特殊Column
能夠水平或垂直放置
檢測它的內容超過顯示框時提供滾動
比Column配置少,但更易於使用並支持滾動app

 


構建ListView有四個選項:less

默認構造函數採用子類的顯式List <Widget>。此構造函數適用於具備少許子項的列表視圖,由於構造List須要爲可能在列表視圖中顯示的每一個子項執行工做,而不單單是那些實際可見的子項。ide

該ListView.builder構造函數採用IndexedWidgetBuilder,它創建在孩子的需求。此構造函數適用於具備大量(或無限)子項數的列表視圖,由於僅爲那些實際可見的子項調用構建器。函數

該ListView.separated構造函數有兩個IndexedWidgetBuilder S: itemBuilder按需創建個子項目,separatorBuilder 一樣創建其出如今子項之間的分隔符的孩子。此構造函數適用於具備固定數量子項的列表視圖。學習

該ListView.custom構造須要SliverChildDelegate,它提供了自定義子模型的其餘方面的能力。例如,SliverChildDelegate能夠控制用於估計實際上不可見的子項大小的算法。ui

 

官方文檔介紹:code


https://docs.flutter.io/flutter/widgets/ListView-class.html

 

案例代碼:

class UITest3_ListView extends StatelessWidget{

  List<Widget> list = <Widget>[
    new ListTile(
      title: new Text('Mi is One',
          style: new TextStyle(fontWeight: FontWeight.w500,fontSize: 20),
      ),
      subtitle: new Text("85 W zq"),
      leading: new Icon(Icons.theaters,color: Colors.blue[500]),
    ),
    new ListTile(
      title: new Text("Test at Tow",style: new TextStyle(fontWeight: FontWeight.w500,fontSize: 20)),
      subtitle: new Text("666 Car"),
      leading: new Icon(Icons.list,color: Colors.blue[500])
    ),
    new ListTile(
      title: new Text('Three',
        style: new TextStyle(fontWeight: FontWeight.w500,fontSize: 20),
      ),
      subtitle: new Text("85 W zq"),
      leading: new Icon(Icons.theaters,color: Colors.blue[500]),
    ),
    new ListTile(
        title: new Text("Four",style: new TextStyle(fontWeight: FontWeight.w500,fontSize: 20)),
        subtitle: new Text("666 Car"),
        leading: new Icon(Icons.list,color: Colors.blue[500]),
        onTap: (){
          Fluttertoast.showToast(
              msg: " Four",
              toastLength: Toast.LENGTH_SHORT,
              gravity: ToastGravity.BOTTOM,
              timeInSecForIos: 1,
              backgroundColor: Colors.blue,
              textColor: Colors.white
          );
        },

    )
  ];


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        title: Text("ListView"),
      ),
      body: new Center(
        child: new ListView(
            children: list,
        ),
      ),
    );
  }
}
相關文章
相關標籤/搜索