Show/hide widgets in Flutter programmatically

前端 未结 13 1308
轮回少年
轮回少年 2020-11-28 04:13

In Android, every single View subclass has a setVisibility() method that allows you modify the visibility of a View object

The

13条回答
  •  再見小時候
    2020-11-28 04:41

    bool _visible = false;
    
     void _toggle() {
        setState(() {
          _visible = !_visible;
        });
      }
    
    onPressed: _toggle,
    
    Visibility(
                visible:_visible,
                child: new Container(
                child: new  Container(
                  padding: EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 10.0),
                  child: new Material(
                    elevation: 10.0,
                    borderRadius: BorderRadius.circular(25.0),
                    child: new ListTile(
                      leading: new Icon(Icons.search),
                      title: new TextField(
                        controller: controller,
                        decoration: new InputDecoration(
                            hintText: 'Search for brands and products', border: InputBorder.none,),
                        onChanged: onSearchTextChanged,
                      ),
                      trailing: new IconButton(icon: new Icon(Icons.cancel), onPressed: () {
                        controller.clear();
                        onSearchTextChanged('');
                      },),
                    ),
                  ),
                ),
              ),
              ),
    

提交回复
热议问题