[material_ui] Port flutter/flutter #181525 "Add keyboard support for RangeSlider" - #12687
[material_ui] Port flutter/flutter #181525 "Add keyboard support for RangeSlider"#12687xxxOVALxxx wants to merge 1 commit into
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);
This PR ports flutter/flutter#181525 from flutter/flutter to flutter/packages.