LoginSignup
3
2

More than 1 year has passed since last update.

【Flutter】画像のプレビュー画面(ピンチイン・ピンチアウト)の作り方

Last updated at Posted at 2023-02-05

よくある画像のピンチイン・ピンチアウトはInteractiveViewerを使用して実装することができます。
ただし、InteractiveViewerだけだと2枚目のスクリーンショットのように画像サイズが固定されてしまい、その中で拡大してしまいます。

InteractiveViewer(
  minScale: 0.1,
  maxScale: 3,
  child: SizedBox(
    width: MediaQuery.of(context).size.width,
    height: MediaQuery.of(context).size.height,
    child: FittedBox(
      child: Image.network("https://picsum.photos/seed/picsum/1500/500"),
    ),
  ),
);

そこで、SizeBoxで外側の大きさをMediaQuery.of(context).sizeにし、FittedBoxで比率を固定しながらリサイズすることで3枚目のように拡大することができます。

元画像 SizedBoxなしの場合 SizedBoxでサイズ指定した場合
1.png 4.png 2.png

色々探してもうまく表示されなかったのでメモ

探したところ

3
2
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
3
2