点击带有渐变叠加的IconButton会中断

时间:2019-06-22 11:35:59

标签: flutter icons flutter-layout

我有一个IconButton,上面有一个渐变叠加层,

Container(
    foregroundDecoration: BoxDecoration(
        gradient: LinearGradient(
            colors: [Colors.orange.shade100, Colors.orange.shade900], 
            begin: Alignment(0, 0), 
            end: Alignment(0, 1)
        ), 
        backgroundBlendMode: BlendMode.screen
    ),
    child: IconButton(
        icon: Icon(Icons.add_box),
        iconSize: 36,
        color: Colors.black,
        onPressed: (){},
    ),
);

enter image description here

在我点击它之前看起来不错,然后渐变突然覆盖了整个Container(和IconButton)并停留在那里。

enter image description here

有没有一种方法可以防止它在点击时破裂?

1 个答案:

答案 0 :(得分:0)

您可以选择将图标包装在容器中,而不是包装整个IconButton。

      IconButton(
        icon: Container(
          foregroundDecoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [Colors.orange.shade100, Colors.orange.shade900],
                begin: Alignment(0, 0),
                end: Alignment(0, 1),
              ),
              backgroundBlendMode: BlendMode.screen),
          child: Icon(Icons.add_box),
        ),
        iconSize: 36,
        color: Colors.black,
        onPressed: () {},
      ),