Skip to content

Conversation

@M97Chahboun
Copy link
Contributor

@M97Chahboun M97Chahboun commented Dec 10, 2024

Adds onHover and onLongPress to IconButton widget

fix #159972

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Dec 10, 2024
@M97Chahboun M97Chahboun marked this pull request as ready for review December 10, 2024 21:24
Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

@M97Chahboun
Looks like your last update made the tests overly complicated. I only suggested to add Column with all icon button variants. We don't need pump each variant like you did in your new update. Please revert to previous version and wrap a Column and add other variants.

Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

Previous tests were simple and cleaner.

This was the suggestion.

          child: Directionality(
            textDirection: TextDirection.ltr,
            child: Column(
              children: [
                IconButton(
                  icon: const Icon(Icons.favorite),
                  onPressed: enabled ? () {} : null,
                  onHover: (bool hover) {
                    onHovered = hover;
                  },
                  onLongPress: () {
                    onLongPressed = true;
                  },
                ),
                /// Add other variants of the IconButton here.
                ],
              ),
            ),
          ),

@M97Chahboun
Copy link
Contributor Author

@TahaTesser Thank you for your suggestion, I will implement it ASAP

@TahaTesser TahaTesser requested a review from bleroux December 13, 2024 16:02
@TahaTesser
Copy link
Member

cc: @bleroux

@M97Chahboun
Copy link
Contributor Author

I tried using a Column, but I encountered a problem with the finder retrieving multiple iconButtons. I researched how to test multiple variants with a single method and found that the testWidgets method has a variant parameter. I used it, but there are some variables outside the method. Is this considered good practice?

I will push the results. Please let me know if this is good practice. If there are any issues, I will revert the commit.

@TahaTesser
Copy link
Member

TahaTesser commented Dec 13, 2024

@M97Chahboun

I understand what you're encountering. You can still use column and put those variants, instead of using just find.byType (because it cannot find variants). Use find.ancestor, you can say ancestor of an icon which is find.byType IconButton.

You can find similar find.ancestor examples in the source code. Also please revert the workaround if you decide to find.ancestor which is much simpler and it is perfect to find such objects.

@TahaTesser
Copy link
Member

I'll be on vacation from now until Jan 2nd, @bleroux can help review this next week.

@bleroux
Copy link
Contributor

bleroux commented Dec 16, 2024

I tried using a Column, but I encountered a problem with the finder retrieving multiple iconButtons.

One simple way to mitigate this, is to set a different icon for each button and use a finder such as:
find.widgetWithIcon(IconButton, Icons.wb_sunny_outlined).

I researched how to test multiple variants with a single method and found that the testWidgets method has a variant parameter. I used it, but there are some variables outside the method. Is this considered good practice?
I will push the results. Please let me know if this is good practice. If there are any issues, I will revert the commit.

testWidgets variant (subclasses of TestVariant) is on over complex feature in the context of this PR.
The main usages of TestVariant is through predefined variants, the main one being TargetPlatformVariant which allow to specify the target platform (iOS, linux, etc) for a test.

Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

LGTM

@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 8, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jan 8, 2025
Merged via the queue into flutter:master with commit 8cc303e Jan 8, 2025
104 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 8, 2025
@M97Chahboun M97Chahboun deleted the add-onhover-and-onlongpress-to-iconbutton branch January 8, 2025 21:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 10, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jan 11, 2025
Roll Flutter from 4b23b81 to 864d4f5 (50 revisions)

flutter/flutter@4b23b81...864d4f5

2025-01-10 [email protected] Mark complex_layout_scroll_perf_macos__timeline_summary unflaky (flutter/flutter#160997)
2025-01-10 [email protected] Mark hello_world_macos__compile unflaky (flutter/flutter#160998)
2025-01-10 [email protected] Mark animated_complex_opacity_perf_macos__e2e_summary unflaky (flutter/flutter#160996)
2025-01-10 [email protected] Mark integration_ui_test_test_macos unflaky (flutter/flutter#160999)
2025-01-10 [email protected] Mark hot_mode_dev_cycle_macos_target__benchmark unflaky (flutter/flutter#161000)
2025-01-10 [email protected] Add a virtual-display (VD) platform view test, and refactor tests a bit. (flutter/flutter#161349)
2025-01-10 [email protected] Remove `CIRRUS_TASK_NAME` from what I can tell, is always omitted on `LUCI` (flutter/flutter#161391)
2025-01-10 [email protected] Replace the always omitted `CPU` environment variable with `numberOfProcessors`. (flutter/flutter#161392)
2025-01-10 [email protected] We no longer have a separate engine repo. (flutter/flutter#161400)
2025-01-10 [email protected] Update Style-guide-for-Flutter-repo.md (flutter/flutter#161344)
2025-01-09 [email protected] integration_test: Add gitignore of golden image (flutter/flutter#161404)
2025-01-09 [email protected] Fix link to engine docs in CONTRIBUTING.md (flutter/flutter#161401)
2025-01-09 [email protected] Roll Packages from 3fc6b7a to 6554751 (11 revisions) (flutter/flutter#161379)
2025-01-09 [email protected] Add `mouseCursor` parameter to `ReorderableListView` (flutter/flutter#160246)
2025-01-09 [email protected] Remove Cirrus CI from Flutter goldens. (flutter/flutter#161396)
2025-01-09 [email protected] remove`useMaterial3: true,` in from the template (flutter/flutter#160525)
2025-01-09 [email protected] Remove `accept_android_sdk_licenses.sh`, which appears unused. (flutter/flutter#161388)
2025-01-09 [email protected] Roll Dart to Version 3.7.0-312.0.dev (flutter/flutter#161394)
2025-01-09 [email protected] Marks Linux analyzer_benchmark to be flaky (flutter/flutter#161307)
2025-01-09 [email protected] [Impeller] fix scaling of trampoline import of GLES textures into Vulkan. (flutter/flutter#161331)
2025-01-09 [email protected] Support DDC library bundle format and remove support for DDC module format (flutter/flutter#161276)
2025-01-09 [email protected] Remove seemingly stale web Cirrus and "Web Installer" instructions (flutter/flutter#161389)
2025-01-09 [email protected] Proposal to deprecate `webGoldenComparator`. (flutter/flutter#161196)
2025-01-09 [email protected] `ImplicitlyAnimatedWidgetState` code cleanup (flutter/flutter#160567)
2025-01-09 [email protected] Exclude `*texture*` as matching for `a: text input` (flutter/flutter#161354)
2025-01-09 [email protected] [Impeller] add opt in flag for SurfaceControl testing. (flutter/flutter#161353)
2025-01-09 [email protected] Roll Dart to Version 3.7.0-307.0.dev (flutter/flutter#161278)
2025-01-09 [email protected] remove formatter from snippet tool (flutter/flutter#161347)
2025-01-09 [email protected] Refactor keyboard manager tests (flutter/flutter#160637)
2025-01-09 [email protected] [flutter_tools] ignore viewpost ime and samsung spam messages. (flutter/flutter#161199)
2025-01-09 [email protected] Revert "[SwiftPM] Add separate feature flag for the app migration (#158897)" (flutter/flutter#161342)
2025-01-09 [email protected] git ignore .ccls-cache (flutter/flutter#161340)
2025-01-08 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[SwiftPM] Turn on by default (#161275)" (flutter/flutter#161339)
2025-01-08 [email protected] Update engine instructions for monorepo (flutter/flutter#161184)
2025-01-08 [email protected] [Impeller] re-enable Adreno 630 (flutter/flutter#161287)
2025-01-08 [email protected] [SwiftPM] Turn on by default (flutter/flutter#161275)
2025-01-08 [email protected] Make the encoding of a `YamlNode` to a `String` more explicit. (flutter/flutter#161270)
2025-01-08 [email protected] Normalize the translation column of the color matrix. (flutter/flutter#161109)
2025-01-08 [email protected] Rename `native_driver` to `android_{driver_extensions|engine_test}` (flutter/flutter#161263)
2025-01-08 [email protected] [Impeller] reland: fix porterduff shader and handle optimized out texture binding in GLES backend. (flutter/flutter#161326)
2025-01-08 [email protected] Updating AVD Dependency for Android 28 Emulator (flutter/flutter#160978)
2025-01-08 [email protected] Adds onHover and onLongPress to IconButton widget (flutter/flutter#160032)
2025-01-08 [email protected] Marks Linux linux_desktop_impeller to be unflaky (flutter/flutter#161302)
2025-01-08 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] porter duff workarounds for Adreno GPU. (#161273)" (flutter/flutter#161318)
2025-01-08 [email protected] Revert "fixed keyboardDismissBehavior on scroll without a drag" (flutter/flutter#161277)
2025-01-08 [email protected] Revert "use uuid from package:uuid instead of from package:usage" (flutter/flutter#161292)
...
srujzs pushed a commit to srujzs/flutter that referenced this pull request Jan 12, 2025
Adds `onHover` and `onLongPress` to `IconButton` widget

fix flutter#159972 

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
Roll Flutter from 4b23b81 to 864d4f5 (50 revisions)

flutter/flutter@4b23b81...864d4f5

2025-01-10 [email protected] Mark complex_layout_scroll_perf_macos__timeline_summary unflaky (flutter/flutter#160997)
2025-01-10 [email protected] Mark hello_world_macos__compile unflaky (flutter/flutter#160998)
2025-01-10 [email protected] Mark animated_complex_opacity_perf_macos__e2e_summary unflaky (flutter/flutter#160996)
2025-01-10 [email protected] Mark integration_ui_test_test_macos unflaky (flutter/flutter#160999)
2025-01-10 [email protected] Mark hot_mode_dev_cycle_macos_target__benchmark unflaky (flutter/flutter#161000)
2025-01-10 [email protected] Add a virtual-display (VD) platform view test, and refactor tests a bit. (flutter/flutter#161349)
2025-01-10 [email protected] Remove `CIRRUS_TASK_NAME` from what I can tell, is always omitted on `LUCI` (flutter/flutter#161391)
2025-01-10 [email protected] Replace the always omitted `CPU` environment variable with `numberOfProcessors`. (flutter/flutter#161392)
2025-01-10 [email protected] We no longer have a separate engine repo. (flutter/flutter#161400)
2025-01-10 [email protected] Update Style-guide-for-Flutter-repo.md (flutter/flutter#161344)
2025-01-09 [email protected] integration_test: Add gitignore of golden image (flutter/flutter#161404)
2025-01-09 [email protected] Fix link to engine docs in CONTRIBUTING.md (flutter/flutter#161401)
2025-01-09 [email protected] Roll Packages from 3fc6b7a to 6554751 (11 revisions) (flutter/flutter#161379)
2025-01-09 [email protected] Add `mouseCursor` parameter to `ReorderableListView` (flutter/flutter#160246)
2025-01-09 [email protected] Remove Cirrus CI from Flutter goldens. (flutter/flutter#161396)
2025-01-09 [email protected] remove`useMaterial3: true,` in from the template (flutter/flutter#160525)
2025-01-09 [email protected] Remove `accept_android_sdk_licenses.sh`, which appears unused. (flutter/flutter#161388)
2025-01-09 [email protected] Roll Dart to Version 3.7.0-312.0.dev (flutter/flutter#161394)
2025-01-09 [email protected] Marks Linux analyzer_benchmark to be flaky (flutter/flutter#161307)
2025-01-09 [email protected] [Impeller] fix scaling of trampoline import of GLES textures into Vulkan. (flutter/flutter#161331)
2025-01-09 [email protected] Support DDC library bundle format and remove support for DDC module format (flutter/flutter#161276)
2025-01-09 [email protected] Remove seemingly stale web Cirrus and "Web Installer" instructions (flutter/flutter#161389)
2025-01-09 [email protected] Proposal to deprecate `webGoldenComparator`. (flutter/flutter#161196)
2025-01-09 [email protected] `ImplicitlyAnimatedWidgetState` code cleanup (flutter/flutter#160567)
2025-01-09 [email protected] Exclude `*texture*` as matching for `a: text input` (flutter/flutter#161354)
2025-01-09 [email protected] [Impeller] add opt in flag for SurfaceControl testing. (flutter/flutter#161353)
2025-01-09 [email protected] Roll Dart to Version 3.7.0-307.0.dev (flutter/flutter#161278)
2025-01-09 [email protected] remove formatter from snippet tool (flutter/flutter#161347)
2025-01-09 [email protected] Refactor keyboard manager tests (flutter/flutter#160637)
2025-01-09 [email protected] [flutter_tools] ignore viewpost ime and samsung spam messages. (flutter/flutter#161199)
2025-01-09 [email protected] Revert "[SwiftPM] Add separate feature flag for the app migration (#158897)" (flutter/flutter#161342)
2025-01-09 [email protected] git ignore .ccls-cache (flutter/flutter#161340)
2025-01-08 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[SwiftPM] Turn on by default (#161275)" (flutter/flutter#161339)
2025-01-08 [email protected] Update engine instructions for monorepo (flutter/flutter#161184)
2025-01-08 [email protected] [Impeller] re-enable Adreno 630 (flutter/flutter#161287)
2025-01-08 [email protected] [SwiftPM] Turn on by default (flutter/flutter#161275)
2025-01-08 [email protected] Make the encoding of a `YamlNode` to a `String` more explicit. (flutter/flutter#161270)
2025-01-08 [email protected] Normalize the translation column of the color matrix. (flutter/flutter#161109)
2025-01-08 [email protected] Rename `native_driver` to `android_{driver_extensions|engine_test}` (flutter/flutter#161263)
2025-01-08 [email protected] [Impeller] reland: fix porterduff shader and handle optimized out texture binding in GLES backend. (flutter/flutter#161326)
2025-01-08 [email protected] Updating AVD Dependency for Android 28 Emulator (flutter/flutter#160978)
2025-01-08 [email protected] Adds onHover and onLongPress to IconButton widget (flutter/flutter#160032)
2025-01-08 [email protected] Marks Linux linux_desktop_impeller to be unflaky (flutter/flutter#161302)
2025-01-08 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] porter duff workarounds for Adreno GPU. (#161273)" (flutter/flutter#161318)
2025-01-08 [email protected] Revert "fixed keyboardDismissBehavior on scroll without a drag" (flutter/flutter#161277)
2025-01-08 [email protected] Revert "use uuid from package:uuid instead of from package:usage" (flutter/flutter#161292)
...
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
Roll Flutter from 4b23b81 to 864d4f5 (50 revisions)

flutter/flutter@4b23b81...864d4f5

2025-01-10 [email protected] Mark complex_layout_scroll_perf_macos__timeline_summary unflaky (flutter/flutter#160997)
2025-01-10 [email protected] Mark hello_world_macos__compile unflaky (flutter/flutter#160998)
2025-01-10 [email protected] Mark animated_complex_opacity_perf_macos__e2e_summary unflaky (flutter/flutter#160996)
2025-01-10 [email protected] Mark integration_ui_test_test_macos unflaky (flutter/flutter#160999)
2025-01-10 [email protected] Mark hot_mode_dev_cycle_macos_target__benchmark unflaky (flutter/flutter#161000)
2025-01-10 [email protected] Add a virtual-display (VD) platform view test, and refactor tests a bit. (flutter/flutter#161349)
2025-01-10 [email protected] Remove `CIRRUS_TASK_NAME` from what I can tell, is always omitted on `LUCI` (flutter/flutter#161391)
2025-01-10 [email protected] Replace the always omitted `CPU` environment variable with `numberOfProcessors`. (flutter/flutter#161392)
2025-01-10 [email protected] We no longer have a separate engine repo. (flutter/flutter#161400)
2025-01-10 [email protected] Update Style-guide-for-Flutter-repo.md (flutter/flutter#161344)
2025-01-09 [email protected] integration_test: Add gitignore of golden image (flutter/flutter#161404)
2025-01-09 [email protected] Fix link to engine docs in CONTRIBUTING.md (flutter/flutter#161401)
2025-01-09 [email protected] Roll Packages from 3fc6b7a to 6554751 (11 revisions) (flutter/flutter#161379)
2025-01-09 [email protected] Add `mouseCursor` parameter to `ReorderableListView` (flutter/flutter#160246)
2025-01-09 [email protected] Remove Cirrus CI from Flutter goldens. (flutter/flutter#161396)
2025-01-09 [email protected] remove`useMaterial3: true,` in from the template (flutter/flutter#160525)
2025-01-09 [email protected] Remove `accept_android_sdk_licenses.sh`, which appears unused. (flutter/flutter#161388)
2025-01-09 [email protected] Roll Dart to Version 3.7.0-312.0.dev (flutter/flutter#161394)
2025-01-09 [email protected] Marks Linux analyzer_benchmark to be flaky (flutter/flutter#161307)
2025-01-09 [email protected] [Impeller] fix scaling of trampoline import of GLES textures into Vulkan. (flutter/flutter#161331)
2025-01-09 [email protected] Support DDC library bundle format and remove support for DDC module format (flutter/flutter#161276)
2025-01-09 [email protected] Remove seemingly stale web Cirrus and "Web Installer" instructions (flutter/flutter#161389)
2025-01-09 [email protected] Proposal to deprecate `webGoldenComparator`. (flutter/flutter#161196)
2025-01-09 [email protected] `ImplicitlyAnimatedWidgetState` code cleanup (flutter/flutter#160567)
2025-01-09 [email protected] Exclude `*texture*` as matching for `a: text input` (flutter/flutter#161354)
2025-01-09 [email protected] [Impeller] add opt in flag for SurfaceControl testing. (flutter/flutter#161353)
2025-01-09 [email protected] Roll Dart to Version 3.7.0-307.0.dev (flutter/flutter#161278)
2025-01-09 [email protected] remove formatter from snippet tool (flutter/flutter#161347)
2025-01-09 [email protected] Refactor keyboard manager tests (flutter/flutter#160637)
2025-01-09 [email protected] [flutter_tools] ignore viewpost ime and samsung spam messages. (flutter/flutter#161199)
2025-01-09 [email protected] Revert "[SwiftPM] Add separate feature flag for the app migration (#158897)" (flutter/flutter#161342)
2025-01-09 [email protected] git ignore .ccls-cache (flutter/flutter#161340)
2025-01-08 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[SwiftPM] Turn on by default (#161275)" (flutter/flutter#161339)
2025-01-08 [email protected] Update engine instructions for monorepo (flutter/flutter#161184)
2025-01-08 [email protected] [Impeller] re-enable Adreno 630 (flutter/flutter#161287)
2025-01-08 [email protected] [SwiftPM] Turn on by default (flutter/flutter#161275)
2025-01-08 [email protected] Make the encoding of a `YamlNode` to a `String` more explicit. (flutter/flutter#161270)
2025-01-08 [email protected] Normalize the translation column of the color matrix. (flutter/flutter#161109)
2025-01-08 [email protected] Rename `native_driver` to `android_{driver_extensions|engine_test}` (flutter/flutter#161263)
2025-01-08 [email protected] [Impeller] reland: fix porterduff shader and handle optimized out texture binding in GLES backend. (flutter/flutter#161326)
2025-01-08 [email protected] Updating AVD Dependency for Android 28 Emulator (flutter/flutter#160978)
2025-01-08 [email protected] Adds onHover and onLongPress to IconButton widget (flutter/flutter#160032)
2025-01-08 [email protected] Marks Linux linux_desktop_impeller to be unflaky (flutter/flutter#161302)
2025-01-08 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] porter duff workarounds for Adreno GPU. (#161273)" (flutter/flutter#161318)
2025-01-08 [email protected] Revert "fixed keyboardDismissBehavior on scroll without a drag" (flutter/flutter#161277)
2025-01-08 [email protected] Revert "use uuid from package:uuid instead of from package:usage" (flutter/flutter#161292)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for onLongPress and onHover callbacks in the IconButton widget

3 participants