[material_ui] Add keyboard support for RangeSlider - #12687
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements keyboard navigation support for the RangeSlider widget, enabling value adjustments via arrow keys in both traditional and directional navigation modes. It introduces shortcut and action mappings, exposes semantic adjustment methods on the render object, and adds tests to verify the behavior. The review feedback recommends avoiding the force-unwrap operator on _renderObjectKey.currentContext in the action handler to prevent potential runtime exceptions if the widget is not fully mounted.
| void _actionHandler(_AdjustSliderIntent intent, Thumb thumb) { | ||
| final slider = _renderObjectKey.currentContext!.findRenderObject()! as _RenderRangeSlider; | ||
| final TextDirection directionality = Directionality.of(_renderObjectKey.currentContext!); |
There was a problem hiding this comment.
To adhere to defensive programming practices, we should avoid using the force-unwrap operator ! on _renderObjectKey.currentContext directly. If the action is triggered during a transition or when the widget is not fully mounted, currentContext could be null, leading to a runtime exception. Checking for null first is safer.
void _actionHandler(_AdjustSliderIntent intent, Thumb thumb) {
final BuildContext? context = _renderObjectKey.currentContext;
if (context == null) {
return;
}
final _RenderRangeSlider slider = context.findRenderObject()! as _RenderRangeSlider;
final TextDirection directionality = Directionality.of(context);|
Thank you for your contribution! Because of the volume of PRs we receive, we require that new contributors use our checklist to guide them through critical steps in creating a Flutter PR. This PR's description is missing that checklist, so it is being marked as a Draft. Please edit the PR description to add the checklist, then ensure that you have completed all of the steps. Once you've done that, please mark the PR as ready for review. If you need help, consider asking for advice on the #hackers-new channel on Discord. |
This PR ports flutter/flutter#181525 from flutter/flutter to flutter/packages.