-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[various] Migrate example Radio groups to new RadioGroup API #10155
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
base: main
Are you sure you want to change the base?
[various] Migrate example Radio groups to new RadioGroup API #10155
Conversation
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. |
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`.
4053511
to
57f7be9
Compare
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.
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. |
Thanks for the contribution!
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.
The repo exemption rule is:
|
f4ca783
to
8f4d89f
Compare
8f4d89f
to
c6cdb22
Compare
@stuartmorgan-g I've updated the format and changelogs using script |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
dcb050f
to
aaba578
Compare
children: <Widget>[ | ||
RadioGroup<T>( | ||
groupValue: selected, | ||
onChanged: (T? v) => (onChanged ?? (_) {})(v), |
There was a problem hiding this comment.
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 ?? (_) {},
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
ad8b151
to
5e347e4
Compare
This PR updates multiple package example apps to stop using deprecated
groupValue
andonChanged
on individualRadio
widgets and instead use the newRadioGroup<T>
ancestor to manage the selected value and change handling.Why
Flutter deprecated
Radio.groupValue
andRadio.onChanged
in favor ofRadioGroup
, 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)
Radio<T>
widgets in aRadioGroup<T>(groupValue: ..., onChanged: ...)
.groupValue
/onChanged
from eachRadio
, leaving onlyvalue
(+ its label UI).animations
demo): old threeRadio
widgets each hadgroupValue
/onChanged
; now they are enclosed in a singleRadioGroup<SharedAxisTransitionType>
and theRadio
children keep just theirvalue
.Packages (examples) updated
animations
camera
camera_android
camera_android_camerax
camera_avfoundation
google_sign_in_web
two_dimensional_scrollables
(bothtable_view
andtree_view
)Screenshots
N/A (UI unchanged; only wiring of radios changed).
Links
Fixes: flutter/flutter#170915
Pre-Review Checklist