Is there any definite list of Sliver widgets

天涯浪子 提交于 2019-12-09 13:17:25

问题


I am trying to use Sliver to implement collapsible list header. As I am changing widgets from normal to Sliver I often end up with error like this:

I/flutter ( 3141): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 3141): The following assertion was thrown building NotificationListener<ScrollNotification>():
I/flutter ( 3141): A RenderViewport expected a child of type RenderSliver but received a child of type
I/flutter ( 3141): RenderRepaintBoundary.
I/flutter ( 3141): RenderObjects expect specific types of children because they coordinate with their children during
I/flutter ( 3141): layout and paint. For example, a RenderSliver cannot be the child of a RenderBox because a
I/flutter ( 3141): RenderSliver does not understand the RenderBox layout protocol.
I/flutter ( 3141):

I/flutter ( 3141): The RenderViewport that expected a RenderSliver child was created by:
I/flutter ( 3141):   Viewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#307856652] ← Listener ← _GestureSemantics ←
I/flutter ( 3141):   RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#701223524] ← RepaintBoundary ←
I/flutter ( 3141):   CustomPaint ← RepaintBoundary ← NotificationListener<ScrollNotification> ←
I/flutter ( 3141):   GlowingOverscrollIndicator ← Scrollable ← ⋯
I/flutter ( 3141):
I/flutter ( 3141): The RenderRepaintBoundary that did not match the expected child type was created by:
I/flutter ( 3141):   RepaintBoundary ← NotificationListener<ScrollNotification> ← GlowingOverscrollIndicator ←
I/flutter ( 3141):   Scrollable ← SingleChildScrollView ← Viewport ← _ScrollableScope ←
I/flutter ( 3141):   IgnorePointer-[GlobalKey#307856652] ← Listener ← _GestureSemantics ←
I/flutter ( 3141):   RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#701223524] ← RepaintBoundary ← ⋯
I/flutter ( 3141):

My understanding is this is because normal widgets can't be used directly to render in Sliver widgets.

Is there any definite list of Sliver widgets in the framework?

sliver.dart doesn't show much


回答1:


The docs for RenderSliver seem to be the closest thing we have to definitive Sliver documentation at the moment.

RenderSliver is implemented by

  • RenderSliverHelpers (mixin)
  • RenderSliverMultiBoxAdaptor (abstract)
    • RenderSliverFixedExtentBoxAdaptor (abstract)
      • _RenderSliverPrototypeExtentList (concrete)
      • RenderSliverFillViewport (concrete)
      • RenderSliverFixedExtentList (concrete)
    • RenderSliverGrid (concrete)
    • RenderSliverList (concrete)
  • RenderSliverPadding (concrete)
  • RenderSliverPersistentHeader (abstract)
    • RenderSliverFloatingPersistentHeader (concrete)
      • RenderSliverFloatingPinnedPersistentHeader (concrete)
    • RenderSliverPinnedPersistentHeader (concrete)
    • RenderSliverScrollingPersistentHeader (concrete)
  • RenderSliverSingleBoxAdapter (abstract)
    • RenderSliverFillRemaining (concrete)
    • RenderSliverToBoxAdapter (concrete)

These RenderSliver implementations are created by the following widgets:

SliverMultiBoxAdaptorWidget subclasses:

  • SliverPrototypeExtentList
  • SliverFillViewport
  • SliverFixedExtentList
  • SliverGrid
  • SliverList

StatelessWidget subclasses:

  • SliverPersistentHeader
    • which is used by SliverAppBar

SingleChildRenderObjectWidget subclasses:

  • SliverFillRemaining
  • SliverPadding
  • SliverToBoxAdapter

So those are the widgets you can use when you want to produce instances of RenderSliver.

Of course, it's likely that more and more RenderSliver-creating widgets will be added over time, and you can also make your own! Hopefully this list will be enough to get you started.



来源:https://stackoverflow.com/questions/44493372/is-there-any-definite-list-of-sliver-widgets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!