Flutterで背景画像をぼかす(ブラー)エフェクトを実装する方法を紹介します。
今回はImageFiltered
を使用して画像をぼかしていきます。
目次
背景画像をぼかす方法
まずはImageFiltered
を使用するためにdart:ui
をインポートします。
import 'dart:ui';
次にImageFiltered
の子ウィジェットで背景画像をぼかしたいウィジェットを指定します。imageFilter
にImageFilter.blur()
を渡し、ImageFilter.blur()
のsigmaX
とsigmaY
にdouble値を渡してぼかしを調整します。
ImageFiltered(
imageFilter: ImageFilter.blur(sigmaX: 15, sigmaY: 15),
child: Image.network(
'https://images.unsplash.com/photo-1627376617965-b8c29ca91aca',
),
)
sigmaX
とsigmaY
の値が0の場合はぼかしのないデフォルトの画像となり、値が高ければ高いほど画像がぼけて表示されます。



サンプルコード
import 'dart:ui';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Flutter')),
body: BackdropFilterExample(),
),
);
}
}
class BackdropFilterExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(30),
child: ImageFiltered(
imageFilter: ImageFilter.blur(sigmaX: 15, sigmaY: 15),
child: Image.network(
'https://images.unsplash.com/photo-1627376617965-b8c29ca91aca'),
),
),
);
}
}
合わせて読みたい
あわせて読みたい


【Flutter】AppBarの戻るボタンを非表示にする
こんにちは、フラメルです。 今回は画面遷移する際にAppBarに自動生成される戻るボタンを非表示にする方法を紹介します。 【AppBarの戻るボタンを非表示にする方法】 戻…
あわせて読みたい


【Flutter】Padding|余白を外側に作る
こんにちは、フラメルです。 今回はPaddingを使用して余白を作る方法を紹介します。 【余白を外側に作る方法】 Paddingあり Paddingなし ウィジェットの外側に余白を作…
あわせて読みたい


【Flutter】Radioの使い方|ラジオボタン(オプションボタン)を実装
FlutterのRadioウィジェットの用途と使い方のまとめ記事です。本記事ではRadioのサンプルコードを使いながら基本的な使い方、知っておきたい基本プロパティを解説してい…