@@ -521,6 +521,113 @@ class SliverFixedExtentList extends SliverMultiBoxAdaptorWidget {
521
521
}
522
522
}
523
523
524
+ /// A sliver that places its box children in a linear array and constrains them
525
+ /// to have the corresponding extent returned by [itemExtentBuilder] .
526
+ ///
527
+ /// _To learn more about slivers, see [CustomScrollView.slivers] ._
528
+ ///
529
+ /// [SliverVariedExtentList] arranges its children in a line along
530
+ /// the main axis starting at offset zero and without gaps. Each child is
531
+ /// constrained to the corresponding extent along the main axis
532
+ /// and the [SliverConstraints.crossAxisExtent] along the cross axis.
533
+ ///
534
+ /// [SliverVariedExtentList] is more efficient than [SliverList] because
535
+ /// [SliverVariedExtentList] does not need to lay out its children to obtain
536
+ /// their extent along the main axis. It's a little more flexible than
537
+ /// [SliverFixedExtentList] because this allow the children to have different extents.
538
+ ///
539
+ /// See also:
540
+ ///
541
+ /// * [SliverFixedExtentList] , whose children are forced to a given pixel
542
+ /// extent.
543
+ /// * [SliverPrototypeExtentList] , which is similar to [SliverFixedExtentList]
544
+ /// except that it uses a prototype list item instead of a pixel value to define
545
+ /// the main axis extent of each item.
546
+ /// * [SliverList] , which does not require its children to have the same
547
+ /// extent in the main axis.
548
+ /// * [SliverFillViewport] , which sizes its children based on the
549
+ /// size of the viewport, regardless of what else is in the scroll view.
550
+ class SliverVariedExtentList extends SliverMultiBoxAdaptorWidget {
551
+ /// Creates a sliver that places box children with the same main axis extent
552
+ /// in a linear array.
553
+ const SliverVariedExtentList ({
554
+ super .key,
555
+ required super .delegate,
556
+ required this .itemExtentBuilder,
557
+ });
558
+
559
+ /// A sliver that places multiple box children in a linear array along the main
560
+ /// axis.
561
+ ///
562
+ /// [SliverVariedExtentList] places its children in a linear array along the main
563
+ /// axis starting at offset zero and without gaps. Each child is forced to have
564
+ /// the returned extent of [itemExtentBuilder] in the main axis and the
565
+ /// [SliverConstraints.crossAxisExtent] in the cross axis.
566
+ ///
567
+ /// This constructor is appropriate for sliver lists with a large (or
568
+ /// infinite) number of children whose extent is already determined.
569
+ ///
570
+ /// Providing a non-null `itemCount` improves the ability of the [SliverGrid]
571
+ /// to estimate the maximum scroll extent.
572
+ SliverVariedExtentList .builder ({
573
+ super .key,
574
+ required NullableIndexedWidgetBuilder itemBuilder,
575
+ required this .itemExtentBuilder,
576
+ ChildIndexGetter ? findChildIndexCallback,
577
+ int ? itemCount,
578
+ bool addAutomaticKeepAlives = true ,
579
+ bool addRepaintBoundaries = true ,
580
+ bool addSemanticIndexes = true ,
581
+ }) : super (delegate: SliverChildBuilderDelegate (
582
+ itemBuilder,
583
+ findChildIndexCallback: findChildIndexCallback,
584
+ childCount: itemCount,
585
+ addAutomaticKeepAlives: addAutomaticKeepAlives,
586
+ addRepaintBoundaries: addRepaintBoundaries,
587
+ addSemanticIndexes: addSemanticIndexes,
588
+ ));
589
+
590
+ /// A sliver that places multiple box children in a linear array along the main
591
+ /// axis.
592
+ ///
593
+ /// [SliverVariedExtentList] places its children in a linear array along the main
594
+ /// axis starting at offset zero and without gaps. Each child is forced to have
595
+ /// the returned extent of [itemExtentBuilder] in the main axis and the
596
+ /// [SliverConstraints.crossAxisExtent] in the cross axis.
597
+ ///
598
+ /// This constructor uses a list of [Widget] s to build the sliver.
599
+ SliverVariedExtentList .list ({
600
+ super .key,
601
+ required List <Widget > children,
602
+ required this .itemExtentBuilder,
603
+ bool addAutomaticKeepAlives = true ,
604
+ bool addRepaintBoundaries = true ,
605
+ bool addSemanticIndexes = true ,
606
+ }) : super (delegate: SliverChildListDelegate (
607
+ children,
608
+ addAutomaticKeepAlives: addAutomaticKeepAlives,
609
+ addRepaintBoundaries: addRepaintBoundaries,
610
+ addSemanticIndexes: addSemanticIndexes,
611
+ ));
612
+
613
+ /// The children extent builder.
614
+ ///
615
+ /// Should return null if asked to build an item extent with a greater index than
616
+ /// exists.
617
+ final ItemExtentBuilder itemExtentBuilder;
618
+
619
+ @override
620
+ RenderSliverVariedExtentList createRenderObject (BuildContext context) {
621
+ final SliverMultiBoxAdaptorElement element = context as SliverMultiBoxAdaptorElement ;
622
+ return RenderSliverVariedExtentList (childManager: element, itemExtentBuilder: itemExtentBuilder);
623
+ }
624
+
625
+ @override
626
+ void updateRenderObject (BuildContext context, RenderSliverVariedExtentList renderObject) {
627
+ renderObject.itemExtentBuilder = itemExtentBuilder;
628
+ }
629
+ }
630
+
524
631
/// A sliver that places multiple box children in a two dimensional arrangement.
525
632
///
526
633
/// _To learn more about slivers, see [CustomScrollView.slivers] ._
0 commit comments