forked from firka/flutter
Fix RangeSlider throws an exception in a ListView (#135667)
fixes [[RangeSlider] [Flutter 3.10] LateInitializationError: Field '_startThumbCenter@280317193' has not been initialized.](https://github.com/flutter/flutter/issues/126648) ### Code sample (Run it on iOS) <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( debugShowCheckedModeBanner: false, home: Example(), ); } } class Example extends StatelessWidget { const Example({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: ListView( children: <Widget>[ const SizedBox( height: 1000, child: Placeholder(), ), RangeSlider( values: const RangeValues(0.25, 0.75), onChanged: (value) {}, ), ], ), ); } } ``` </details>
This commit is contained in:
@@ -900,8 +900,8 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
|
||||
late TapGestureRecognizer _tap;
|
||||
bool _active = false;
|
||||
late RangeValues _newValues;
|
||||
late Offset _startThumbCenter;
|
||||
late Offset _endThumbCenter;
|
||||
Offset _startThumbCenter = Offset.zero;
|
||||
Offset _endThumbCenter = Offset.zero;
|
||||
Rect? overlayStartRect;
|
||||
Rect? overlayEndRect;
|
||||
|
||||
|
||||
@@ -2541,7 +2541,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgetsWithLeakTracking('RangeSlider onChangeStart and onChangeEnd fire once', (WidgetTester tester) async {
|
||||
testWidgetsWithLeakTracking('RangeSlider onChangeStart and onChangeEnd fire once', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/128433
|
||||
|
||||
int startFired = 0;
|
||||
@@ -2581,4 +2581,34 @@ void main() {
|
||||
expect(startFired, equals(1));
|
||||
expect(endFired, equals(1));
|
||||
});
|
||||
|
||||
testWidgetsWithLeakTracking('RangeSlider in a ListView does not throw an exception', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/126648
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Material(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
const SizedBox(
|
||||
height: 600,
|
||||
child: Placeholder(),
|
||||
),
|
||||
RangeSlider(
|
||||
values: const RangeValues(40, 80),
|
||||
max: 100,
|
||||
onChanged: (RangeValues newValue) { },
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// No exception should be thrown.
|
||||
expect(tester.takeException(), null);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user