Steps to Reproduce
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'List playground',
home: TestPage(),
);
}
}
class TestPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
List<String> items = ['1', '2', '3', '4', '5'];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SizedBox(
width: 44.4,
height: 30.0,
child: Directionality(
textDirection: TextDirection.ltr,
child: CustomScrollView(
slivers: <Widget>[
SliverFixedExtentList(
itemExtent: 22.2,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return TextWidget(
items[index],
);
},
childCount : items.length,
),
),
],
),
),
),
),
);
}
}
class TextWidget extends StatefulWidget {
const TextWidget(this.data);
final String data;
@override
TextWidgetState createState() => TextWidgetState();
}
class TextWidgetState extends State<TextWidget>{
@override
void dispose() {
print('disposed ${widget.data}');
super.dispose();
}
@override
Widget build(BuildContext context) {
return Text(widget.data);
}
}
When scrolling the sliver in the middle, It should disposes the elements that are not in view. Actual, it doesn't dispose them.
It turns out in RenderSliverFixedExtentBoxAdaptor.constraints.scrollOffset is always zero no matter how far you drag the scroll view, so it does not do the garbage collection to remove the widget that are not in view.
Steps to Reproduce
When scrolling the sliver in the middle, It should disposes the elements that are not in view. Actual, it doesn't dispose them.
It turns out in RenderSliverFixedExtentBoxAdaptor.constraints.scrollOffset is always zero no matter how far you drag the scroll view, so it does not do the garbage collection to remove the widget that are not in view.