Unverified Commit d134345f authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

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>
parent 449c9279
......@@ -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;
......
......@@ -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);
});
}
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