forked from firka/flutter
Adds a first draft of LazyBlock
LazyBlock is intended as a replacement for MixedViewport. Rather than maintaining a table of all the observed child sizes (like MixedViewport), LazyBlock works by dead reckoning the location of the children based on the existing viewport. This approach makes it easier to resize children because LazyBlock doesn't cache any additional information that would need to be invalidated. This patch contains a first draft of LazyBlock that works in a simple usage scenario. Subsequent patches will replace ScrollableMixedWidgetList with LazyBlock and port the existing ScrollableMixedWidgetList tests over to LazyBlock. Related to #3075
This commit is contained in:
@@ -49,6 +49,19 @@ class ComplexLayout extends StatefulWidget {
|
||||
|
||||
}
|
||||
|
||||
class FancyItemDelegate extends LazyBlockDelegate {
|
||||
@override
|
||||
Widget buildItem(BuildContext context, int index) {
|
||||
if (index % 2 == 0)
|
||||
return new FancyImageItem(index, key: new Key("Item $index"));
|
||||
else
|
||||
return new FancyGalleryItem(index, key: new Key("Item $index"));
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRebuild(FancyItemDelegate oldDelegate) => false;
|
||||
}
|
||||
|
||||
class ComplexLayoutState extends State<ComplexLayout> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -70,14 +83,9 @@ class ComplexLayoutState extends State<ComplexLayout> {
|
||||
body: new Column(
|
||||
children: <Widget>[
|
||||
new Flexible(
|
||||
child: new ScrollableMixedWidgetList(
|
||||
child: new LazyBlock(
|
||||
key: new Key("main-scroll"),
|
||||
builder: (BuildContext context, int index) {
|
||||
if (index % 2 == 0)
|
||||
return new FancyImageItem(index, key: new Key("Item $index"));
|
||||
else
|
||||
return new FancyGalleryItem(index, key: new Key("Item $index"));
|
||||
}
|
||||
delegate: new FancyItemDelegate()
|
||||
)
|
||||
),
|
||||
new BottomBar()
|
||||
|
||||
Reference in New Issue
Block a user