Skip to content

Instantly share code, notes, and snippets.

@ciriousjoker
Last active February 26, 2025 20:48
Show Gist options
  • Save ciriousjoker/ac93d3f7b93eb62fca01d3cacea17e71 to your computer and use it in GitHub Desktop.
Save ciriousjoker/ac93d3f7b93eb62fca01d3cacea17e71 to your computer and use it in GitHub Desktop.
repro: BackdropFilter+AnimatedScale (flutter/flutter#164235)
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(
body: Stack(
children: [
Positioned.fill(child: Placeholder()),
TapResponse(
child: Stack(children: [FrostedSurface(), Text("Hello World")]),
),
],
),
),
);
}
}
class TapResponse extends StatefulWidget {
final Widget child;
const TapResponse({super.key, required this.child});
@override
State<TapResponse> createState() => _TapResponseState();
}
class _TapResponseState extends State<TapResponse> {
// Current scale factor for the animation.
double _scale = 1.0;
void _handlePointerDown(PointerDownEvent event) {
setState(() => _scale = 0.98);
}
void _handlePointerUp(PointerUpEvent event) {
setState(() => _scale = 1.0);
}
void _handlePointerCancel(PointerCancelEvent event) {
setState(() => _scale = 1.0);
}
@override
Widget build(BuildContext context) {
return Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: _handlePointerDown,
onPointerUp: _handlePointerUp,
onPointerCancel: _handlePointerCancel,
child: AnimatedScale(
scale: _scale,
duration: Duration(milliseconds: 300),
filterQuality: FilterQuality.high,
child: widget.child,
),
);
}
}
class FrostedSurface extends StatelessWidget {
const FrostedSurface({super.key});
@override
Widget build(BuildContext context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment