Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button icon support for animation duration #162667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Feb 4, 2025

Fixes Default foreground color animation duration doesn't apply on icon of Button widgets
Fixes Implement similar widget toAnimatedDefaultTextStyle but for child Icon

Description

This PR adds``AnimatedThemetoButtonStyleButton` which is extended by buttons. It animates the button icon when changing icon color and size, similar to button text.

Code Sample

expand to view the code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          spacing: 20,
          children: <Widget>[
            ElevatedButton.icon(
              icon: const Icon(Icons.favorite_rounded, size: 50),
              label: const Text('Button', style: TextStyle(fontSize: 36)),
              onPressed: () {},
              style: const ButtonStyle(
                iconColor: WidgetStateProperty<Color>.fromMap(
                  <WidgetStatesConstraint, Color>{
                    WidgetState.pressed: Color(0XFFFF0000),
                    WidgetState.any: Color(0XFF000000),
                  },
                ),
                foregroundColor: WidgetStateProperty<Color>.fromMap(
                  <WidgetStatesConstraint, Color>{
                    WidgetState.pressed: Color(0XFFFF0000),
                    WidgetState.any: Color(0XFF000000),
                  },
                ),
              ),
            ),
            ElevatedButton.icon(
              icon: const Icon(Icons.favorite_rounded, size: 50),
              label: const Text('Button', style: TextStyle(fontSize: 36)),
              onPressed: () {},
              style: const ButtonStyle(
                animationDuration: Duration(seconds: 2),
                iconColor: WidgetStateProperty<Color>.fromMap(
                  <WidgetStatesConstraint, Color>{
                    WidgetState.pressed: Color(0XFFFF0000),
                    WidgetState.any: Color(0XFF000000),
                  },
                ),
                foregroundColor: WidgetStateProperty<Color>.fromMap(
                  <WidgetStatesConstraint, Color>{
                    WidgetState.pressed: Color(0XFFFF0000),
                    WidgetState.any: Color(0XFF000000),
                  },
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

Before

before.mp4

After

after.mp4

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Feb 4, 2025
@TahaTesser TahaTesser force-pushed the button_icon_animation_duration branch 8 times, most recently from 322fc87 to 29f9b78 Compare February 10, 2025 09:07
@TahaTesser TahaTesser force-pushed the button_icon_animation_duration branch from 29f9b78 to 327b200 Compare February 13, 2025 08:21
@TahaTesser TahaTesser force-pushed the button_icon_animation_duration branch from 327b200 to 575d86e Compare February 14, 2025 14:50
@TahaTesser TahaTesser marked this pull request as ready for review February 14, 2025 16:03
Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! LGTM. Thanks! Curious whether this will cause any g3fix🫣

@@ -490,9 +490,11 @@ void main() {
}

await tester.pumpWidget(buildFrame(appIconColor: Colors.lime));
await tester.pumpAndSettle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change because of the newly added AnimatedTheme in ButtonStyleButton?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Themes requires tester.pumpAndSettle to rebuild the widget with updated theme.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience, when testing widget parameter and theme parameter in the same tests always requires tester.pumpAndSettle. These tests are doing the same.

@justinmc
Copy link
Contributor

Indeed this has broken Google tests.

@TahaTesser
Copy link
Member Author

TahaTesser commented Mar 4, 2025

@QuncCccccc
Could you please check broken Google tests?

@QuncCccccc
Copy link
Contributor

Ah missed this one. Yes! I'll take a look!

@QuncCccccc QuncCccccc self-requested a review March 14, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
3 participants