颤振:全底按钮,带安全区域

时间:2020-10-21 17:08:16

标签: flutter flutter-layout

我遇到了这个问题:我找到了唯一的解决方法,即在iPhone 11上使用safearea时,按钮的背景处于全高。但是现在,部分按下了podskajet。请作为按钮如何按下整个蓝色区域。谢谢大家的答案。 我添加了屏幕截图和一段代码,因为它现在已经实现。

enter image description here

      Container(
        color: Colors.blue,
        child: SafeArea(
          left: false,
          right: false,
          child: Expanded(
            flex: 1,
            child: SizedBox(
              width: double.infinity,
              child: RaisedButton(
                elevation: 0,
                onPressed: () {},
                child: Text("Add", style: TextStyle(color: Colors.white)),
                color: Colors.blue,
              ),
            ),
          ),
        ),
      ),

1 个答案:

答案 0 :(得分:1)

您可以通过更改此容器的颜色进行检查。

   Container(
    color: Colors.red,

或者您可以通过inspector使用Debug Paint。然后您将意识到按钮中没有某些区域。这就是onTap无法正常工作的原因。

在那之后,您可以轻松使用InkWell来包装所有容器。

  InkWell(
      onTap: () {
       // Here is your onTap function
      },
      Container(
        color: Colors.red,
        child: SafeArea(
          left: false,
          right: false,
          child: Expanded(
            flex: 1,
            child: SizedBox(
              width: double.infinity,
              // In fact, you don't need a button anymore.
              child: RaisedButton(
                elevation: 0,
                onPressed: () {},
                child: Text("Add", style: TextStyle(color: Colors.white)),
                color: Colors.blue,
          ),
        ),
       ),
      ),
     ),
    ),