Skip to content

Conversation

alexskobozev
Copy link

@alexskobozev alexskobozev commented Oct 1, 2025

This PR updates multiple package example apps to stop using deprecated groupValue and onChanged on individual Radio widgets and instead use the new RadioGroup<T> ancestor to manage the selected value and change handling.

Why

Flutter deprecated Radio.groupValue and Radio.onChanged in favor of RadioGroup, which centralizes selection state for related radios. The deprecation is currently reported across several examples in this repo (see linked issue for examples and affected packages). This PR resolves those warnings.

What changed (pattern applied across examples)

  • Wrap related Radio<T> widgets in a RadioGroup<T>(groupValue: ..., onChanged: ...).
  • Remove groupValue/onChanged from each Radio, leaving only value (+ its label UI).
    • Example (from animations demo): old three Radio widgets each had groupValue/onChanged; now they are enclosed in a single RadioGroup<SharedAxisTransitionType> and the Radio children keep just their value.

Packages (examples) updated

  • animations
  • camera
  • camera_android
  • camera_android_camerax
  • camera_avfoundation
  • google_sign_in_web
  • two_dimensional_scrollables (both table_view and tree_view)

Screenshots

N/A (UI unchanged; only wiring of radios changed).

Links

Fixes: flutter/flutter#170915


Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets (multi-package format used).
  • I [linked to at least one issue that this PR fixes] in the description above.
  • Version/CHANGELOG
  • I updated/added any relevant documentation (N/A for example code).
  • I added new tests to check the change I am making (N/A; example code only).
  • All existing and new tests are passing.

Copy link

google-cla bot commented Oct 1, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@alexskobozev alexskobozev changed the title Handle deprecated radio examples [animations][camera][camera_android][camera_android_camerax][camera_avfoundation][google_sign_in_web][two_dimensional_scrollables] Migrate example Radio groups to new RadioGroup API Oct 1, 2025
@alexskobozev alexskobozev marked this pull request as ready for review October 1, 2025 10:08
Refactors the `shared_axis_transition.dart` example to use a new `RadioGroup` widget. This removes the deprecated `groupValue` and `onChanged` properties from each individual `Radio` button
Refactors the camera example to use a new `RadioGroup` widget. This removes deprecated `groupValue` and `onChanged` properties from each individual `RadioListTile` and moves them to the parent `RadioGroup`.
Refactors the camera example to use a new `RadioGroup` widget. This removes deprecated `groupValue` and `onChanged` properties from each individual `RadioListTile` and moves them to the parent `RadioGroup`.
Refactors the `camera_android_camerax` example to use a new `RadioGroup` widget. This removes the deprecated `groupValue` and `onChanged` properties from each individual `RadioListTile` and moves them to the parent `RadioGroup`.
Refactors the `camera_avfoundation` example to use a new `RadioGroup` widget. This removes deprecated `onChanged` logic from each `RadioListTile` and moves it to the parent `RadioGroup`.
Refactors the `google_sign_in_web` example to use a new `RadioGroup` widget. This removes the deprecated `groupValue` and `onChanged` properties from each individual `RadioListTile` and moves them to the parent `RadioGroup`.
Refactors the `two_dimensional_scrollables` example to use a new `RadioGroup` widget. This removes the deprecated `groupValue` and `onChanged` properties from each individual `Radio` button and moves them to the parent `RadioGroup`.
@alexskobozev alexskobozev force-pushed the handle_deprecated_radio_examples branch from 4053511 to 57f7be9 Compare October 1, 2025 10:21
Removes `const` from `Text` widgets inside a `Row` that was not itself `const`, and adds `const` to the `Row` itself.
Adds `const` to constructors and curly braces to control flow statements to fix new lint warnings in the `table_explorer.dart` and `tree_explorer.dart` examples.
Formats the `main.dart` file in the example application to align with current project standards. This change primarily involves code formatting and does not alter any functionality.
@stuartmorgan-g stuartmorgan-g changed the title [animations][camera][camera_android][camera_android_camerax][camera_avfoundation][google_sign_in_web][two_dimensional_scrollables] Migrate example Radio groups to new RadioGroup API [various] Migrate example Radio groups to new RadioGroup API Oct 1, 2025
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@stuartmorgan-g
Copy link
Collaborator

Thanks for the contribution!

  • I read and followed the [relevant style guides] and ran [the auto-formatter].

You've applied non-standard formatting; please see the CI failures for details. It looks like either you didn't run the current version of the auto-formatter, or you are applying custom line length rules.

  • Version/CHANGELOG: Exempt. Changes are limited to example apps; no published packages modified (per repo exemption rules).

The repo exemption rule is:

PRs that only affect unpublished parts of example apps.

lib/main.dart is published on pub.dev, and most of the changes in this PR are to lib/main.dart files.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft October 1, 2025 12:05
@alexskobozev alexskobozev force-pushed the handle_deprecated_radio_examples branch from f4ca783 to 8f4d89f Compare October 2, 2025 07:21
@alexskobozev alexskobozev force-pushed the handle_deprecated_radio_examples branch from 8f4d89f to c6cdb22 Compare October 2, 2025 08:40
@alexskobozev alexskobozev marked this pull request as ready for review October 2, 2025 09:39
@alexskobozev
Copy link
Author

alexskobozev commented Oct 2, 2025

@stuartmorgan-g I've updated the format and changelogs using script

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Reviewed for animation and two_dimensional_scrollables - I think these would be good to release so that the example reflect the updated APIs from stable.

@@ -1,5 +1,6 @@
## NEXT
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would we not want to release the updated sample code?

Copy link
Collaborator

Choose a reason for hiding this comment

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

pub.dev only shows lib/main.dart, and the changes in this package aren't to that file, so publishing wouldn't do anything (unless people are running examples out of their pub cache, but that's not something we expect/support in the repo policy).

@@ -1,5 +1,6 @@
## NEXT
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same applies here; the changes aren't to lib/main.dart.

required String title,
required List<T> values,
T? selected,
void Function(T?)? onChanged,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this ever null? If so, this is also a behavior change for the same reason. (If not, it should be replumbed through the file to be non-nullable.)

Choose a reason for hiding this comment

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

It can be null in button tester to support the state when there are no auth credentials.
Added enabled attribute instead of nullable onChanged since it has the same behaviour. Thanks for the catch
Before on/off (nullable onChanged)
before_on
before_off

After on/off (enabled attribute)
after_on
after_off

This reverts commit f6b2de3.
Disables the `RadioListTile` widgets in the example when their `onChanged` callback is null. This provides a visual indication that the options are not selectable.

The change also simplifies the `onChanged` handler logic within the `RadioGroup`.
Disables the `RadioListTile` widgets for camera selection while a video is being recorded. This prevents the user from attempting to switch cameras during a recording session, which is not a supported action.
@alexskobozev alexskobozev force-pushed the handle_deprecated_radio_examples branch from dcb050f to aaba578 Compare October 3, 2025 12:37
children: <Widget>[
RadioGroup<T>(
groupValue: selected,
onChanged: (T? v) => (onChanged ?? (_) {})(v),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of the wrapping function here? This seems much more complicated than just doing onChanged: onChanged ?? (_) {},

Copy link
Author

@alexskobozev alexskobozev Oct 6, 2025

Choose a reason for hiding this comment

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

Replaced this with onChanged: onChanged ?? (_) {}, but seems if we run flutter run -d chrome --target=lib/button_tester.dart radiogroup is not working. Found that onChanged ?? (_) {} just returns a function, it never calls it. That’s why the callback in RadioGroup is never triggered. The wrapper actually invokes the callback with the selected value. Without it, the radios don’t switch because nothing ever notifies the group.

Copy link
Author

Choose a reason for hiding this comment

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

But you're right, I've simplified it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Found that onChanged ?? (_) {} just returns a function, it never calls it.

I don't follow. That expression is supposed to return a function without calling it, because it's providing a function as a parameter.

In this line for example, onChanged is a function reference, not a function call.

Simplifies the `onChanged` callback in the `RadioGroup` widget by using a null-aware `call` instead of a null-coalescing operator with an empty function.
@alexskobozev alexskobozev force-pushed the handle_deprecated_radio_examples branch from ad8b151 to 5e347e4 Compare October 6, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[packages] groupValue and onChanged are deprecated
4 participants