Created
September 21, 2023 19:46
-
-
Save jonahwilliams/504c3a5d6adb5b0bd4900cc8fa023c2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'dart:ui'; | |
import 'package:flutter/material.dart'; | |
final _random = Random(); | |
void main() => runApp(const BackdropFilterDemo()); | |
class BackdropFilterDemo extends StatelessWidget { | |
const BackdropFilterDemo({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
backgroundColor: Colors.black, | |
body: Stack( | |
children: [ | |
ListView.separated( | |
separatorBuilder: (_, __) => const SizedBox(height: 8), | |
itemBuilder: (context, index) => BlurEffect( | |
child: Container( | |
height: 50, | |
color: Colors.primaries[_random.nextInt(17)].shade300, | |
child: Center( | |
child: Text(index.toString()), | |
), | |
), | |
), | |
itemCount: 200, | |
), | |
Positioned.fill( | |
bottom: null, | |
child: BlurEffect( | |
child: Padding( | |
padding: EdgeInsets.only( | |
top: MediaQuery.of(context).viewPadding.top, | |
), | |
child: const SizedBox(height: 45), | |
), | |
), | |
), | |
Positioned.fill( | |
top: null, | |
child: BlurEffect( | |
child: Padding( | |
padding: EdgeInsets.only( | |
top: MediaQuery.of(context).viewPadding.bottom, | |
), | |
child: const SizedBox(height: 50), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class BlurEffect extends StatelessWidget { | |
final Widget child; | |
const BlurEffect({ | |
required this.child, | |
Key? key, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return ClipRect( | |
child: BackdropFilter( | |
filter: ImageFilter.blur( | |
sigmaX: 28, | |
sigmaY: 28, | |
tileMode: TileMode.mirror, | |
), | |
child: DecoratedBox( | |
decoration: BoxDecoration(color: Colors.black.withOpacity(.65)), | |
child: child, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment