how to create toolbar searchview in flutter

前端 未结 6 1300
不思量自难忘°
不思量自难忘° 2020-12-02 13:19

i need to implement searchview in toolbar my app to achieve list view list filter. like below image, i searched lot still not get proper answer. Any help will be appreciated

6条回答
  •  青春惊慌失措
    2020-12-02 13:59

    You just need to alternate between the state whenever the user taps on the icon. Beside a little bit of refactoring an code cleaning on your side, this simple example should get you going.

    class SearchAppBar extends StatefulWidget {
      @override
      _SearchAppBarState createState() => new _SearchAppBarState();
    }
    
    class _SearchAppBarState extends State {
      Widget appBarTitle = new Text("AppBar Title");
      Icon actionIcon = new Icon(Icons.search);
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            centerTitle: true,
            title:appBarTitle,
            actions: [
              new IconButton(icon: actionIcon,onPressed:(){
              setState(() {
                         if ( this.actionIcon.icon == Icons.search){
                          this.actionIcon = new Icon(Icons.close);
                          this.appBarTitle = new TextField(
                            style: new TextStyle(
                              color: Colors.white,
    
                            ),
                            decoration: new InputDecoration(
                              prefixIcon: new Icon(Icons.search,color: Colors.white),
                              hintText: "Search...",
                              hintStyle: new TextStyle(color: Colors.white)
                            ),
                          );}
                          else {
                            this.actionIcon = new Icon(Icons.search);
                            this.appBarTitle = new Text("AppBar Title");
                          }
    
    
                        });
            } ,),]
          ),
        );
      }
    }
    

提交回复
热议问题