【问题标题】:Flutter: Expanded IconButton still shows under the ContainerFlutter:扩展的 IconButton 仍然显示在 Container 下
【发布时间】:2021-01-18 04:43:07
【问题描述】:
       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 小部件一样。当AnimatedContainerText 小部件一样被拉伸时,我怎样才能让它出现?

【问题讨论】:

    标签: flutter


    【解决方案1】:

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

    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,
                        ),
                      ],
                    ),
                  )
    
                ],
              ),
            )
          ]),
        );
      }
    }
    

    【讨论】:

    • 该死!没想到这样用 Stack!
    猜你喜欢
    • 2021-03-21
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 2021-08-31
    • 2016-11-05
    • 2019-09-21
    • 2022-01-25
    • 2019-07-17
    相关资源
    最近更新 更多