Skip to content

Conversation

@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented May 15, 2017

An efficient sliver list where the extent of each child is defined by the size of one "prototype" item.

SliverPrototypeExtentList is very similar to SliverFixedExtentList. Instead of providing an itemExtent pixel value, you provide a prototypeItem widget. The prototype item's size along the main axis defines the size of the extent of each list child. The prototype is not painted and it does not respond to input.

Here's a simple example:

import 'package:flutter/material.dart';

class SliverPrototypeItemListDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: const Text('SliverPrototypeExtentList'),
      ),
      body: new CustomScrollView(
        slivers: <Widget>[
          new SliverPrototypeExtentList(
            prototypeItem: const CardItem(item: 0),
            delegate: new SliverChildBuilderDelegate(
              (BuildContext context, int index) => new CardItem(item: index),
              childCount: 50,
            ),
          ),
        ],
      ),
    );
  }
}

/// Displays its integer item as 'item $item' on a Card whose color is based on
/// the item's value.
class CardItem extends StatelessWidget {
  const CardItem({ Key key, this.item }) : super(key: key);

  final int item;

  @override
  Widget build(BuildContext context) {
    final MaterialColor cardColors = Colors.primaries[item % Colors.primaries.length];
    final Color cardColor = cardColors.shade400;
    return new Padding(
      padding: const EdgeInsets.all(2.0),
      child: new Card(
        color: cardColor,
        child: new Padding(
          padding: const EdgeInsets.all(16.0),
          child: new Center(
            child: new Text('Item $item', style: Theme.of(context).textTheme.display1),
          ),
        ),
      ),
    );
  }
}

void main() {
  runApp(new MaterialApp(home: new SliverPrototypeItemListDemo()));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this'll work for the case of moving a child from the list to the prototype entry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that wasn't supposed to be there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you keep everything in this file, you should probably make everything except the widget private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, there's no need to expose anything else.

@HansMuller HansMuller force-pushed the sliver_prototype_extent_list branch from 9bfa82e to 8a0a35b Compare May 16, 2017 00:51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, "instead of"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's many more examples of "intead a" below, all of which should be fixed too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma before "in"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put the public class first, to make this file's context easier to understand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i really understand that comment.
maybe // this method never gets called for the prototype?
also maybe also assert that child != renderObject.child?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the prototype is also one of the children then I think child == renderObject.child is OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the RenderObject, not the widget. It can't be in two places at once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use different words than "linear array" in this paragraph since otherwise it's just repeating the last paragraph

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lay out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace "which has a configurable [itemExtent]" with "whose [itemExtent] is configured in pixels" or some such

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot

@Hixie
Copy link
Contributor

Hixie commented May 16, 2017

LGTM

@Hixie
Copy link
Contributor

Hixie commented May 16, 2017

This is great.

@HansMuller HansMuller force-pushed the sliver_prototype_extent_list branch from 546dcce to 4b58324 Compare May 16, 2017 18:10
@Hixie
Copy link
Contributor

Hixie commented May 16, 2017

The examples/catalog/lib/basic_app_bar.dart changes are unrelated enough to the rest of the PR that we should probably move it to a separate PR.

@HansMuller HansMuller merged commit 765e5d5 into flutter:master May 16, 2017
a-siva added a commit that referenced this pull request Jul 25, 2019
flutter/engine@72341ed03 Roll fuchsia/sdk/core/linux-amd64 from gQ3ztEQmdEh3iE6n9EO6iGRdmDSX-edmP5WyE-Ui4BEC to gTG1jp04GzBudVJqRxulXYOEQgbYTUQgnqLDYAq7z3sC (#10115)
flutter/engine@d66031f2a Roll src/third_party/dart 82f657d7cb..0c97c31b6e (7 commits) (#10114)
flutter/engine@f742514a5 Cache font family lookups that fail to obtain a font collection (#10109)
flutter/engine@7c177724c Roll fuchsia/sdk/core/mac-amd64 from A21rwGAUjpjVTX8HgpT9Iyx6J_QZBRDhu-5GAclrf00C to UCAnzi4k9pA30l_iZ2Ru51Tc3Ke6iacIdjFMgVUVdRMC (#10107)
flutter/engine@c3165da09 Roll src/third_party/skia fdf4bfe6d389..b3956dc6ba6a (1 commits) (#10101)
flutter/engine@71702b3f8 Roll fuchsia/sdk/core/linux-amd64 from gPDgr6u-BPJTgV2Nf0tlg9MTY3JwGW0cETtsQcx365AC to gQ3ztEQmdEh3iE6n9EO6iGRdmDSX-edmP5WyE-Ui4BEC (#10103)
flutter/engine@f393da22d [fuchsia] copy over the cmx file (#10087)
flutter/engine@8ebd15d26 Roll src/third_party/skia f564f1515bde..fdf4bfe6d389 (1 commits) (#10100)
flutter/engine@f529a251b Roll fuchsia/sdk/core/mac-amd64 from lvLKs8Q4CKm_XLoZCQ72RO0RHI6yvJXnA9M_M8r4-aAC to A21rwGAUjpjVTX8HgpT9Iyx6J_QZBRDhu-5GAclrf00C (#10099)
flutter/engine@d409df823 Roll src/third_party/dart 9c148623c5..82f657d7cb (25 commits)
flutter/engine@acd139ce6 Roll src/third_party/skia 1cd1ed8976c4..f564f1515bde (1 commits) (#10097)
flutter/engine@f2c9da4a0 Roll src/third_party/skia 3ae30cc2e6e0..1cd1ed8976c4 (1 commits) (#10096)
flutter/engine@d2f0b9ef1 Roll fuchsia/sdk/core/linux-amd64 from MCDItwEzechMpZAiI0QOzuiTtNUGArUa4TprH0Er-7QC to gPDgr6u-BPJTgV2Nf0tlg9MTY3JwGW0cETtsQcx365AC (#10095)
flutter/engine@0f4db494a Roll fuchsia/sdk/core/mac-amd64 from EH_61w2lpSn0UmpJkynWM6tiT0nnKk1GhTRRKK2cGMwC to lvLKs8Q4CKm_XLoZCQ72RO0RHI6yvJXnA9M_M8r4-aAC (#10094)
flutter/engine@298799991 Roll src/third_party/skia 0f9c660aa939..3ae30cc2e6e0 (1 commits) (#10093)
flutter/engine@a4d2d3648 Roll fuchsia/sdk/core/linux-amd64 from tCzkXNr7cb5OAbS5NcJ4F_g0DgVj3w8rfbT14AcaTHoC to MCDItwEzechMpZAiI0QOzuiTtNUGArUa4TprH0Er-7QC (#10090)
flutter/engine@d27a6373d Roll fuchsia/sdk/core/mac-amd64 from xNAaLqZJk8Bkz00BaHGzE8hCpiohggO7KabM3g2wdsQC to EH_61w2lpSn0UmpJkynWM6tiT0nnKk1GhTRRKK2cGMwC (#10089)
flutter/engine@20dc17282 Roll src/third_party/skia d15571af2e1b..0f9c660aa939 (1 commits) (#10088)
flutter/engine@9e7260b9d Roll fuchsia/sdk/core/linux-amd64 from kU0OwJYlceN477ejdh9RXrl7Mp-wUTNvQozlaV96xmQC to tCzkXNr7cb5OAbS5NcJ4F_g0DgVj3w8rfbT14AcaTHoC (#10086)
flutter/engine@0e621d902 [fuchsia] Use the new far package model (#10085)
flutter/engine@bdc713695 [fuchsia] Add sysroot and clang libs to package (#10082)
flutter/engine@72f747ae4 Roll fuchsia/clang/linux-amd64 from apsjZJ9ZIwlS08divc0QwxuNgIFeN4X-52mKR9d8qacC to zHiuOGMDwdWPUkV1B2fHKyRy2fGWGcUgfa2z6dyGAZQC (#10084)
flutter/engine@bfe689ee8 Roll fuchsia/clang/mac-amd64 from USm3Qt9wen4bXoFF0T9Xt8NX-pyEfte2cTYi7geLAhQC to UYD9C8IEkWVi83ef4zwO1Ump2B8cP9Nd5WECjU8l3AUC (#10083)
flutter/engine@cf5d76c17 [fuchsia] Add support for libs in packages (#10081)
flutter/engine@c4c64896a Roll src/third_party/skia 829144cc76fe..d15571af2e1b (2 commits) (#10080)
flutter/engine@25e5d597e Roll fuchsia/sdk/core/linux-amd64 from S_24mhItBb7pfUof8zsJPPSctC7xdlfjDEXEtyO25GYC to kU0OwJYlceN477ejdh9RXrl7Mp-wUTNvQozlaV96xmQC (#10079)
flutter/engine@f7e0614b8 Change ParagraphBuilder to replace the parent style's font families with the child style's font families (#10074)
flutter/engine@eb74f2ce7 One more luci fix (#10078)
flutter/engine@6e732c7f1 Change flutter runner target for LUCI (#10075)
flutter/engine@44ec59b70 Roll src/third_party/dart fedd74669a..9c148623c5 (70 commits) (#10066)
flutter/engine@abf93699f Basic structure for flutter_jit_runner far (#10073)
flutter/engine@3c76b90b2 Track clusters and return cluster boundaries in getGlyphPositionForCoordinates (emoji fix) (#10063)
flutter/engine@e8fb641f6 Enable consts from environment in DDK for flutter_web (#10069)
flutter/engine@bd3870219 [macos] Revert check on FlutterCodecs and refactor message function] (#10009)
flutter/engine@d6e1a93e2 Roll src/third_party/skia e11dfd3da4d7..829144cc76fe (4 commits) (#10072)
flutter/engine@d595af681 Roll fuchsia/sdk/core/linux-amd64 from XqtWTBni4xpYCTr7gqU7rFTuXNY1TZ_zOqBJrZM8c_kC to S_24mhItBb7pfUof8zsJPPSctC7xdlfjDEXEtyO25GYC (#10071)
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
flutter/engine@72341ed03 Roll fuchsia/sdk/core/linux-amd64 from gQ3ztEQmdEh3iE6n9EO6iGRdmDSX-edmP5WyE-Ui4BEC to gTG1jp04GzBudVJqRxulXYOEQgbYTUQgnqLDYAq7z3sC (flutter#10115)
flutter/engine@d66031f2a Roll src/third_party/dart 82f657d7cb..0c97c31b6e (7 commits) (flutter#10114)
flutter/engine@f742514a5 Cache font family lookups that fail to obtain a font collection (flutter#10109)
flutter/engine@7c177724c Roll fuchsia/sdk/core/mac-amd64 from A21rwGAUjpjVTX8HgpT9Iyx6J_QZBRDhu-5GAclrf00C to UCAnzi4k9pA30l_iZ2Ru51Tc3Ke6iacIdjFMgVUVdRMC (flutter#10107)
flutter/engine@c3165da09 Roll src/third_party/skia fdf4bfe6d389..b3956dc6ba6a (1 commits) (flutter#10101)
flutter/engine@71702b3f8 Roll fuchsia/sdk/core/linux-amd64 from gPDgr6u-BPJTgV2Nf0tlg9MTY3JwGW0cETtsQcx365AC to gQ3ztEQmdEh3iE6n9EO6iGRdmDSX-edmP5WyE-Ui4BEC (flutter#10103)
flutter/engine@f393da22d [fuchsia] copy over the cmx file (flutter#10087)
flutter/engine@8ebd15d26 Roll src/third_party/skia f564f1515bde..fdf4bfe6d389 (1 commits) (flutter#10100)
flutter/engine@f529a251b Roll fuchsia/sdk/core/mac-amd64 from lvLKs8Q4CKm_XLoZCQ72RO0RHI6yvJXnA9M_M8r4-aAC to A21rwGAUjpjVTX8HgpT9Iyx6J_QZBRDhu-5GAclrf00C (flutter#10099)
flutter/engine@d409df823 Roll src/third_party/dart 9c148623c5..82f657d7cb (25 commits)
flutter/engine@acd139ce6 Roll src/third_party/skia 1cd1ed8976c4..f564f1515bde (1 commits) (flutter#10097)
flutter/engine@f2c9da4a0 Roll src/third_party/skia 3ae30cc2e6e0..1cd1ed8976c4 (1 commits) (flutter#10096)
flutter/engine@d2f0b9ef1 Roll fuchsia/sdk/core/linux-amd64 from MCDItwEzechMpZAiI0QOzuiTtNUGArUa4TprH0Er-7QC to gPDgr6u-BPJTgV2Nf0tlg9MTY3JwGW0cETtsQcx365AC (flutter#10095)
flutter/engine@0f4db494a Roll fuchsia/sdk/core/mac-amd64 from EH_61w2lpSn0UmpJkynWM6tiT0nnKk1GhTRRKK2cGMwC to lvLKs8Q4CKm_XLoZCQ72RO0RHI6yvJXnA9M_M8r4-aAC (flutter#10094)
flutter/engine@298799991 Roll src/third_party/skia 0f9c660aa939..3ae30cc2e6e0 (1 commits) (flutter#10093)
flutter/engine@a4d2d3648 Roll fuchsia/sdk/core/linux-amd64 from tCzkXNr7cb5OAbS5NcJ4F_g0DgVj3w8rfbT14AcaTHoC to MCDItwEzechMpZAiI0QOzuiTtNUGArUa4TprH0Er-7QC (flutter#10090)
flutter/engine@d27a6373d Roll fuchsia/sdk/core/mac-amd64 from xNAaLqZJk8Bkz00BaHGzE8hCpiohggO7KabM3g2wdsQC to EH_61w2lpSn0UmpJkynWM6tiT0nnKk1GhTRRKK2cGMwC (flutter#10089)
flutter/engine@20dc17282 Roll src/third_party/skia d15571af2e1b..0f9c660aa939 (1 commits) (flutter#10088)
flutter/engine@9e7260b9d Roll fuchsia/sdk/core/linux-amd64 from kU0OwJYlceN477ejdh9RXrl7Mp-wUTNvQozlaV96xmQC to tCzkXNr7cb5OAbS5NcJ4F_g0DgVj3w8rfbT14AcaTHoC (flutter#10086)
flutter/engine@0e621d902 [fuchsia] Use the new far package model (flutter#10085)
flutter/engine@bdc713695 [fuchsia] Add sysroot and clang libs to package (flutter#10082)
flutter/engine@72f747ae4 Roll fuchsia/clang/linux-amd64 from apsjZJ9ZIwlS08divc0QwxuNgIFeN4X-52mKR9d8qacC to zHiuOGMDwdWPUkV1B2fHKyRy2fGWGcUgfa2z6dyGAZQC (flutter#10084)
flutter/engine@bfe689ee8 Roll fuchsia/clang/mac-amd64 from USm3Qt9wen4bXoFF0T9Xt8NX-pyEfte2cTYi7geLAhQC to UYD9C8IEkWVi83ef4zwO1Ump2B8cP9Nd5WECjU8l3AUC (flutter#10083)
flutter/engine@cf5d76c17 [fuchsia] Add support for libs in packages (flutter#10081)
flutter/engine@c4c64896a Roll src/third_party/skia 829144cc76fe..d15571af2e1b (2 commits) (flutter#10080)
flutter/engine@25e5d597e Roll fuchsia/sdk/core/linux-amd64 from S_24mhItBb7pfUof8zsJPPSctC7xdlfjDEXEtyO25GYC to kU0OwJYlceN477ejdh9RXrl7Mp-wUTNvQozlaV96xmQC (flutter#10079)
flutter/engine@f7e0614b8 Change ParagraphBuilder to replace the parent style's font families with the child style's font families (flutter#10074)
flutter/engine@eb74f2ce7 One more luci fix (flutter#10078)
flutter/engine@6e732c7f1 Change flutter runner target for LUCI (flutter#10075)
flutter/engine@44ec59b70 Roll src/third_party/dart fedd74669a..9c148623c5 (70 commits) (flutter#10066)
flutter/engine@abf93699f Basic structure for flutter_jit_runner far (flutter#10073)
flutter/engine@3c76b90b2 Track clusters and return cluster boundaries in getGlyphPositionForCoordinates (emoji fix) (flutter#10063)
flutter/engine@e8fb641f6 Enable consts from environment in DDK for flutter_web (flutter#10069)
flutter/engine@bd3870219 [macos] Revert check on FlutterCodecs and refactor message function] (flutter#10009)
flutter/engine@d6e1a93e2 Roll src/third_party/skia e11dfd3da4d7..829144cc76fe (4 commits) (flutter#10072)
flutter/engine@d595af681 Roll fuchsia/sdk/core/linux-amd64 from XqtWTBni4xpYCTr7gqU7rFTuXNY1TZ_zOqBJrZM8c_kC to S_24mhItBb7pfUof8zsJPPSctC7xdlfjDEXEtyO25GYC (flutter#10071)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants