|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:ui' as ui; |
| 6 | +import 'package:flutter/material.dart'; |
| 7 | + |
| 8 | +// Various tests to verify that Animated image filtered layers do not |
| 9 | +// dirty children even without explicit repaint boundaries. These intentionally use |
| 10 | +// text to ensure we don't measure the opacity peephole case. |
| 11 | +class AnimatedComplexImageFiltered extends StatefulWidget { |
| 12 | + const AnimatedComplexImageFiltered({ super.key }); |
| 13 | + |
| 14 | + @override |
| 15 | + State<AnimatedComplexImageFiltered> createState() => _AnimatedComplexImageFilteredState(); |
| 16 | +} |
| 17 | + |
| 18 | +class _AnimatedComplexImageFilteredState extends State<AnimatedComplexImageFiltered> with SingleTickerProviderStateMixin { |
| 19 | + late final AnimationController controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 5000)); |
| 20 | + late final Animation<double> animation = controller.drive(Tween<double>(begin: 0.0, end: 1.0)); |
| 21 | + ui.ImageFilter imageFilter = ui.ImageFilter.blur(); |
| 22 | + |
| 23 | + @override |
| 24 | + void initState() { |
| 25 | + super.initState(); |
| 26 | + controller.repeat(); |
| 27 | + animation.addListener(() { |
| 28 | + setState(() { |
| 29 | + imageFilter = ui.ImageFilter.blur(sigmaX: animation.value * 5, sigmaY: animation.value * 5); |
| 30 | + }); |
| 31 | + }); |
| 32 | + } |
| 33 | + |
| 34 | + @override |
| 35 | + void dispose() { |
| 36 | + controller.dispose(); |
| 37 | + super.dispose(); |
| 38 | + } |
| 39 | + |
| 40 | + @override |
| 41 | + Widget build(BuildContext context) { |
| 42 | + return MaterialApp( |
| 43 | + home: Scaffold( |
| 44 | + body: ListView( |
| 45 | + children: <Widget>[ |
| 46 | + for (int i = 0; i < 20; i++) |
| 47 | + ImageFiltered( |
| 48 | + imageFilter: imageFilter, |
| 49 | + child: Center( |
| 50 | + child: Transform.scale(scale: 1.01, child: const ModeratelyComplexWidget()), |
| 51 | + ), |
| 52 | + ), |
| 53 | + ], |
| 54 | + ), |
| 55 | + ), |
| 56 | + ); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +class ModeratelyComplexWidget extends StatelessWidget { |
| 61 | + const ModeratelyComplexWidget({ super.key }); |
| 62 | + |
| 63 | + @override |
| 64 | + Widget build(BuildContext context) { |
| 65 | + return const Material( |
| 66 | + elevation: 10, |
| 67 | + clipBehavior: Clip.hardEdge, |
| 68 | + child: ListTile( |
| 69 | + leading: Icon(Icons.abc, size: 24), |
| 70 | + title: DecoratedBox(decoration: BoxDecoration(color: Colors.red), child: Text('Hello World')), |
| 71 | + trailing: FlutterLogo(), |
| 72 | + ), |
| 73 | + ); |
| 74 | + } |
| 75 | +} |
0 commit comments