mirror of
https://github.com/flutter/flutter.git
synced 2026-01-21 05:04:42 +08:00
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)
This commit is contained in:
parent
cf8d20f70f
commit
5aa6cb857d
@ -1628,10 +1628,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
|
||||
}
|
||||
|
||||
/// Describe the semantics of the start thumb.
|
||||
SemanticsNode? _startSemanticsNode = SemanticsNode();
|
||||
SemanticsNode? _startSemanticsNode;
|
||||
|
||||
/// Describe the semantics of the end thumb.
|
||||
SemanticsNode? _endSemanticsNode = SemanticsNode();
|
||||
SemanticsNode? _endSemanticsNode;
|
||||
|
||||
// Create the semantics configuration for a single value.
|
||||
SemanticsConfiguration _createSemanticsConfiguration(
|
||||
@ -1697,6 +1697,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
|
||||
width: kMinInteractiveDimension,
|
||||
height: kMinInteractiveDimension,
|
||||
);
|
||||
|
||||
_startSemanticsNode ??= SemanticsNode();
|
||||
_endSemanticsNode ??= SemanticsNode();
|
||||
|
||||
switch (textDirection) {
|
||||
case TextDirection.ltr:
|
||||
_startSemanticsNode!.rect = leftRect;
|
||||
|
||||
@ -9,6 +9,8 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/src/physics/utils.dart' show nearEqual;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
void main() {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/105833
|
||||
testWidgets('Drag gesture uses provided gesture settings', (WidgetTester tester) async {
|
||||
@ -2610,4 +2612,36 @@ void main() {
|
||||
// No exception should be thrown.
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user