From 02a510ae7952a72b31da8ac44af93d9b9118eade Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 17 Aug 2026 13:04:05 -0700 Subject: [PATCH 1/2] Port animated theme test from flutter/flutter. This test was created from Widgets tests in https://github.com/flutter/flutter/pull/186673, but the change never made it over to flutter/packages. --- .../material_ui/test/animated_theme_test.dart | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 packages/material_ui/test/animated_theme_test.dart diff --git a/packages/material_ui/test/animated_theme_test.dart b/packages/material_ui/test/animated_theme_test.dart new file mode 100644 index 00000000000..6f278ffdcf5 --- /dev/null +++ b/packages/material_ui/test/animated_theme_test.dart @@ -0,0 +1,101 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class _MockOnEndFunction { + int called = 0; + + void handler() { + called++; + } +} + +const Duration _animationDuration = Duration(milliseconds: 1000); +const Duration _additionalDelay = Duration(milliseconds: 1); + +void main() { + late _MockOnEndFunction mockOnEndFunction; + const switchKey = Key('switchKey'); + + setUp(() { + mockOnEndFunction = _MockOnEndFunction(); + }); + + testWidgets('AnimatedTheme onEnd callback test', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: _TestAnimatedThemeWidget( + callback: mockOnEndFunction.handler, + switchKey: switchKey, + ), + ), + ), + ); + + final Finder widgetFinder = find.byKey(switchKey); + + await tester.tap(widgetFinder); + + await tester.pump(); + expect(mockOnEndFunction.called, 0); + await tester.pump(_animationDuration); + expect(mockOnEndFunction.called, 0); + await tester.pump(_additionalDelay); + expect(mockOnEndFunction.called, 1); + + await tester.tap(widgetFinder); + + await tester.pump(); + await tester.pump(_animationDuration + _additionalDelay); + expect(mockOnEndFunction.called, 2); + + await tester.tap(widgetFinder); + + await tester.pump(); + await tester.pump(_animationDuration + _additionalDelay); + expect(mockOnEndFunction.called, 3); + }); +} + +class _TestAnimatedThemeWidget extends StatefulWidget { + const _TestAnimatedThemeWidget({this.callback, required this.switchKey}); + + final VoidCallback? callback; + final Key switchKey; + + @override + State<_TestAnimatedThemeWidget> createState() => _TestAnimatedThemeWidgetState(); +} + +class _TestAnimatedThemeWidgetState extends State<_TestAnimatedThemeWidget> { + bool toggle = false; + + @override + Widget build(BuildContext context) { + return Stack( + children: [ + AnimatedTheme( + data: toggle ? ThemeData.dark() : ThemeData(), + duration: _animationDuration, + onEnd: widget.callback, + child: const Placeholder(), + ), + GestureDetector( + key: widget.switchKey, + behavior: HitTestBehavior.opaque, + onTap: () { + setState(() { + toggle = !toggle; + }); + }, + child: const SizedBox(width: 48.0, height: 48.0), + ), + ], + ); + } +} From 40a717602235c6a68acc66a98333ce01404f1334 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 17 Aug 2026 14:27:40 -0700 Subject: [PATCH 2/2] Correct license --- packages/material_ui/test/animated_theme_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material_ui/test/animated_theme_test.dart b/packages/material_ui/test/animated_theme_test.dart index 6f278ffdcf5..f58da402bad 100644 --- a/packages/material_ui/test/animated_theme_test.dart +++ b/packages/material_ui/test/animated_theme_test.dart @@ -1,4 +1,4 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. +// Copyright 2013 The Flutter Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.