0
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で画像やウィジェットを左右反転、上下反転する方法

Last updated at Posted at 2023-10-24

画像(ImageWidget)を左右反転したかったのでググっていたのですがあまり日本語での情報がなかったので備忘録として書き遺しておきます

ウィジェットを左右反転させる

Transform.scaleを使います。

Column(
  children: [
    Image.network('https://picsum.photos/250?image=9'),
    SizedBox(height:15),
    Transform.scale(
      scaleX: -1,
      child: Image.network('https://picsum.photos/250?image=9'),
    ),
    Text("テスト----"),
    Transform.scale(
      scaleX: -1,
      child: Text("テスト----"),
    ),
  ],
),

スクリーンショット 2023-10-24 19.42.20.png

また、

Transform.flip(
    flipX: true,
    child: Image.network('https://picsum.photos/250?image=9'),
),

のような書き方もできます。
動作は同じですがこっちのが直感的でいいですね...

ウィジェットを上下反転させる

左右反転の時はscaleX: -1,を用いていましたが、scaleY: -1,に変更します。

Column(
  children: [
    Image.network('https://picsum.photos/250?image=9'),
    SizedBox(height:15),
    Transform.scale(
      scaleY: -1,
      child: Image.network('https://picsum.photos/250?image=9'),
    ),
    Text("テスト----"),
    Transform.scale(
      scaleY: -1,
      child: Text("テスト----"),
    ),
  ],
),

スクリーンショット 2023-10-24 19.46.00.png

お役に立てば幸いです。

0
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
0
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?