首页 > 解决方案 > Flutter:扩展的 IconButton 仍然显示在 Container 下

问题描述

       AnimatedContainer(
               ...
                child: Container(
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Container(
                            width:60,
                            height:50,
                            color: Colors.black,
                          ),
                        ],
                      ),
                      Expanded(
                        child: GestureDetector(
                            onTap: () {
                              print('what');
                            },
                            child: Container(
                              height: 50,
                              child: Column(
                                children: [
                                  Expanded(
                                    child: Text('asdf'),
                                  ),
                                  Expanded(
                                    child: IconButton(
                                      icon: Icon(Icons.ac_unit),
                                      onPressed: () {},
                                    ),

AnimatedContainer这里有这个小部件。我的Text()小部件和RaisedButton小部件隐藏在盒子内。它们显示为AnimatedContainer展开。但是,我IconButton没有。

在此处输入图像描述

此外,Icon小部件也像IconButton小部件一样。AnimatedContainer当像小部件一样拉伸时,我怎样才能让它出现Text

在此处输入图像描述

标签: flutter

解决方案


我已经修改了你的代码,希望这是你想要的。

class _RowStructureState extends State<RowStructure> {
  bool pressed = false;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        setState(() {
          pressed = !pressed;
        });
        print(pressed);
      },
      child: Column(children: <Widget>[
        AnimatedContainer(
          height: pressed ? 120 : 50,
          color: Colors.green,
          duration: Duration(seconds: 1),
          child: Stack(
            children: [
              Container(
                height: 50,
                width: 50,
                color: Colors.black,
              ),
              Positioned(
                bottom:0,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Text('asd'),
                    IconButton(
                      padding: EdgeInsets.all(0),
                      icon: Icon(Icons.ac_unit,),
                      onPressed: pressed?(){}:null,
                    ),
                  ],
                ),
              )

            ],
          ),
        )
      ]),
    );
  }
}

推荐阅读