Unverified Commit 5aa6cb85 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `RangeSlider` throws a null-check error after `clearSemantics` is called (#141965)

fixes [Null-check operator on RangeSlider's _startSemanticsNode](https://github.com/flutter/flutter/issues/141953)
parent cf8d20f7
...@@ -1628,10 +1628,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1628,10 +1628,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
} }
/// Describe the semantics of the start thumb. /// Describe the semantics of the start thumb.
SemanticsNode? _startSemanticsNode = SemanticsNode(); SemanticsNode? _startSemanticsNode;
/// Describe the semantics of the end thumb. /// Describe the semantics of the end thumb.
SemanticsNode? _endSemanticsNode = SemanticsNode(); SemanticsNode? _endSemanticsNode;
// Create the semantics configuration for a single value. // Create the semantics configuration for a single value.
SemanticsConfiguration _createSemanticsConfiguration( SemanticsConfiguration _createSemanticsConfiguration(
...@@ -1697,6 +1697,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1697,6 +1697,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
width: kMinInteractiveDimension, width: kMinInteractiveDimension,
height: kMinInteractiveDimension, height: kMinInteractiveDimension,
); );
_startSemanticsNode ??= SemanticsNode();
_endSemanticsNode ??= SemanticsNode();
switch (textDirection) { switch (textDirection) {
case TextDirection.ltr: case TextDirection.ltr:
_startSemanticsNode!.rect = leftRect; _startSemanticsNode!.rect = leftRect;
......
...@@ -9,6 +9,8 @@ import 'package:flutter/rendering.dart'; ...@@ -9,6 +9,8 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/src/physics/utils.dart' show nearEqual; import 'package:flutter/src/physics/utils.dart' show nearEqual;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart';
void main() { void main() {
// Regression test for https://github.com/flutter/flutter/issues/105833 // Regression test for https://github.com/flutter/flutter/issues/105833
testWidgets('Drag gesture uses provided gesture settings', (WidgetTester tester) async { testWidgets('Drag gesture uses provided gesture settings', (WidgetTester tester) async {
...@@ -2610,4 +2612,36 @@ void main() { ...@@ -2610,4 +2612,36 @@ void main() {
// No exception should be thrown. // No exception should be thrown.
expect(tester.takeException(), null); expect(tester.takeException(), null);
}); });
// This is a regression test for https://github.com/flutter/flutter/issues/141953.
testWidgets('Semantic nodes do not throw an error after clearSemantics', (WidgetTester tester) async {
SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: RangeSlider(
values: const RangeValues(40, 80),
max: 100,
onChanged: (RangeValues newValue) { },
),
),
),
);
// Dispose the semantics to trigger clearSemantics.
semantics.dispose();
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
// Initialize the semantics again.
semantics = SemanticsTester(tester);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
semantics.dispose();
}, semanticsEnabled: false);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment