如何在颤动列表视图中实现搜索功能?

时间:2019-07-13 09:07:26

标签: flutter dart flutter-layout flutter-dependencies dart-pub

我在Flutter应用中使用了列表视图。我想在该列表中执行搜索。我不想在操作栏中搜索,而是要在列表本身中搜索。有人可以帮我吗?

这是我的ListTile代码:

new Column(
          children: <Widget>[
      new Padding(
      padding: new EdgeInsets.all(8.0),
      child: new TextField(
        controller: searchController,
        decoration: InputDecoration(
          hintText: 'Search...',

          contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
          border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(32.0)),
        ),
      ),

This implements design part but i don't know how to implement logic

Here is my ListTile code



    class BankDetailList extends StatelessWidget {
      final List<BankDetail> bankdetail;
      BankDetailList({Key key, this.bankdetail}) : super(key: key);
      TextEditingController searchController = new TextEditingController();
      String filter;
      @override
      Widget build(BuildContext context) {

//here is the List Tile code..    
        ListTile makeListTile(BankDetail bankDetail) => ListTile(
          contentPadding:
          EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
          leading: Container(
            padding: EdgeInsets.only(right: 12.0),
            decoration: new BoxDecoration(
                border: new Border(
                    right: new BorderSide(width: 1.0, color: Colors.white24))),
            child: Icon(Icons.account_balance, color: Colors.white),
          ),
          title: Text(
            '${bankDetail.bank_name}',
            style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold,fontSize: 14.0),

          ),
          // subtitle: Text("Intermediate", style: TextStyle(color: 

Colors.white)),

      subtitle: Row(
        children: <Widget>[
          Expanded(
              flex: 0,
              child: Container(
                // tag: 'hero',
                /*child: LinearProgressIndicator(
                    backgroundColor: Color.fromRGBO(209, 224, 224, 0.2),
               //     value: lesson.indicatorValue,
                    valueColor: AlwaysStoppedAnimation(Colors.green)),*/
              )),
          Expanded(
            flex: 4,
            child: Padding(
                padding: EdgeInsets.only(left: 0.0),
                child: Text("Swift Code : "+bankDetail.swift_code,
                    style: TextStyle(color: Colors.white,fontSize: 12))),
          ),
          new Text('${bankDetail.city_name}',
          style : TextStyle(color:Colors.white,fontSize: 10),

          )


        ],

     ),
      trailing:
      Icon(Icons.keyboard_arrow_right, color: Colors.white, size: 30.0),
      onTap: ()

      {
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => DetailPage()));
      },



    );

    Card makeCard(BankDetail bankDetail) => Card(
      elevation: 8.0,
      margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
      child: Container(
        decoration: BoxDecoration(color: Color.fromRGBO(64, 75, 96, .9)),
        child: makeListTile(bankDetail),
      ),
    );

    final makeBody = Container(


      // decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, 1.0)),
      child: ListView.builder(
        scrollDirection: Axis.vertical,
        shrinkWrap: true,
        itemCount: bankdetail.length,
        itemBuilder: (BuildContext context, int index) {
          return makeCard(bankdetail[index]);
        },
      ),
    );

    final makeBottom = Container(
      height: 55.0,
      child: BottomAppBar(
        color: Color.fromRGBO(58, 66, 86, 1.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.home, color: Colors.white),
              onPressed: () {},
            ),
            IconButton(
              icon: Icon(Icons.blur_on, color: Colors.white),
              onPressed: () {},
            ),
            IconButton(
              icon: Icon(Icons.hotel, color: Colors.white),
              onPressed: () {},
            ),
            IconButton(
              icon: Icon(Icons.account_box, color: Colors.white),
              onPressed: () {},
            )
          ],
        ),
      ),
    );
    final topAppBar = AppBar(
      elevation: 0.1,
      backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
      title: Text("Bank Details"),
      actions: <Widget>[
        IconButton(
          icon: Icon(Icons.list),
          onPressed: () {},
        )
      ],
    );

    return Scaffold(
      backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
      appBar: topAppBar,
      body: /*new Column(
          children: <Widget>[
      new Padding(
      padding: new EdgeInsets.all(8.0),
      child: new TextField(
        controller: searchController,
        decoration: InputDecoration(
          hintText: 'Search...',

          contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
          border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(32.0)),
        ),
      ),
    ),new Expanded(child:*/ makeBody,





      bottomNavigationBar: makeBottom,
    );

  }


}

0 个答案:

没有答案