Skip to content

Sliver garbage collect does not work in Sizedbox #36305

@chunhtai

Description

@chunhtai

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.found in release: 3.3Found to occur in 3.3found in release: 3.6Found to occur in 3.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions