1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

FlutterでOpacityウィジェットを使わずに半透明にさせる方法

Last updated at Posted at 2023-10-21

やりたいこと

Flutterでは、OpacityWidgetを使うことでウィジェットを透明にすることができます。
しかし以下のような状態で、赤色のContainerのみを半透明にしたい場合は別の方法を使わないといけません。

スクリーンショット 2023-10-21 14.47.47.png
↑青い部分まで透明化してしまっている

解決法

Colorプロパティの.withOpacityを使う

Container(
    height : 100,
    width : 100,

    color: Colors.red.withOpacity(0.5),
                      ^^^^^^^^^^^^^^^^

    alignment: Alignment.center,
    child : Container(
        height : 50,
        width : 50,
        color : Colors.blueAccent,
    ),
),

こうすることで以下のように.withOpacityを使ったウィジェットのみ、半透明にさせることができます。

スクリーンショット 2023-10-21 14.59.37.png

お役に立てば幸いです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?