Unverified Commit 9464661a authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix sample code (#67940)

parent 7f1540f3
...@@ -61,7 +61,7 @@ typedef NestedScrollViewHeaderSliversBuilder = List<Widget> Function(BuildContex ...@@ -61,7 +61,7 @@ typedef NestedScrollViewHeaderSliversBuilder = List<Widget> Function(BuildContex
/// (those inside the [TabBarView], hooking them together so that they appear, /// (those inside the [TabBarView], hooking them together so that they appear,
/// to the user, as one coherent scroll view. /// to the user, as one coherent scroll view.
/// ///
/// {@tool sample --template=stateless_widget_scaffold} /// {@tool sample --template=stateless_widget_material}
/// ///
/// This example shows a [NestedScrollView] whose header is the combination of a /// This example shows a [NestedScrollView] whose header is the combination of a
/// [TabBar] in a [SliverAppBar] and whose body is a [TabBarView]. It uses a /// [TabBar] in a [SliverAppBar] and whose body is a [TabBarView]. It uses a
...@@ -76,101 +76,103 @@ typedef NestedScrollViewHeaderSliversBuilder = List<Widget> Function(BuildContex ...@@ -76,101 +76,103 @@ typedef NestedScrollViewHeaderSliversBuilder = List<Widget> Function(BuildContex
/// final List<String> _tabs = ['Tab 1', 'Tab 2']; /// final List<String> _tabs = ['Tab 1', 'Tab 2'];
/// return DefaultTabController( /// return DefaultTabController(
/// length: _tabs.length, // This is the number of tabs. /// length: _tabs.length, // This is the number of tabs.
/// child: NestedScrollView( /// child: Scaffold(
/// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { /// body: NestedScrollView(
/// // These are the slivers that show up in the "outer" scroll view. /// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
/// return <Widget>[ /// // These are the slivers that show up in the "outer" scroll view.
/// SliverOverlapAbsorber( /// return <Widget>[
/// // This widget takes the overlapping behavior of the SliverAppBar, /// SliverOverlapAbsorber(
/// // and redirects it to the SliverOverlapInjector below. If it is /// // This widget takes the overlapping behavior of the SliverAppBar,
/// // missing, then it is possible for the nested "inner" scroll view /// // and redirects it to the SliverOverlapInjector below. If it is
/// // below to end up under the SliverAppBar even when the inner /// // missing, then it is possible for the nested "inner" scroll view
/// // scroll view thinks it has not been scrolled. /// // below to end up under the SliverAppBar even when the inner
/// // This is not necessary if the "headerSliverBuilder" only builds /// // scroll view thinks it has not been scrolled.
/// // widgets that do not overlap the next sliver. /// // This is not necessary if the "headerSliverBuilder" only builds
/// handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), /// // widgets that do not overlap the next sliver.
/// sliver: SliverAppBar( /// handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
/// title: const Text('Books'), // This is the title in the app bar. /// sliver: SliverAppBar(
/// pinned: true, /// title: const Text('Books'), // This is the title in the app bar.
/// expandedHeight: 150.0, /// pinned: true,
/// // The "forceElevated" property causes the SliverAppBar to show /// expandedHeight: 150.0,
/// // a shadow. The "innerBoxIsScrolled" parameter is true when the /// // The "forceElevated" property causes the SliverAppBar to show
/// // inner scroll view is scrolled beyond its "zero" point, i.e. /// // a shadow. The "innerBoxIsScrolled" parameter is true when the
/// // when it appears to be scrolled below the SliverAppBar. /// // inner scroll view is scrolled beyond its "zero" point, i.e.
/// // Without this, there are cases where the shadow would appear /// // when it appears to be scrolled below the SliverAppBar.
/// // or not appear inappropriately, because the SliverAppBar is /// // Without this, there are cases where the shadow would appear
/// // not actually aware of the precise position of the inner /// // or not appear inappropriately, because the SliverAppBar is
/// // scroll views. /// // not actually aware of the precise position of the inner
/// forceElevated: innerBoxIsScrolled, /// // scroll views.
/// bottom: TabBar( /// forceElevated: innerBoxIsScrolled,
/// // These are the widgets to put in each tab in the tab bar. /// bottom: TabBar(
/// tabs: _tabs.map((String name) => Tab(text: name)).toList(), /// // These are the widgets to put in each tab in the tab bar.
/// tabs: _tabs.map((String name) => Tab(text: name)).toList(),
/// ),
/// ), /// ),
/// ), /// ),
/// ), /// ];
/// ]; /// },
/// }, /// body: TabBarView(
/// body: TabBarView( /// // These are the contents of the tab views, below the tabs.
/// // These are the contents of the tab views, below the tabs. /// children: _tabs.map((String name) {
/// children: _tabs.map((String name) { /// return SafeArea(
/// return SafeArea( /// top: false,
/// top: false, /// bottom: false,
/// bottom: false, /// child: Builder(
/// child: Builder( /// // This Builder is needed to provide a BuildContext that is
/// // This Builder is needed to provide a BuildContext that is /// // "inside" the NestedScrollView, so that
/// // "inside" the NestedScrollView, so that /// // sliverOverlapAbsorberHandleFor() can find the
/// // sliverOverlapAbsorberHandleFor() can find the /// // NestedScrollView.
/// // NestedScrollView. /// builder: (BuildContext context) {
/// builder: (BuildContext context) { /// return CustomScrollView(
/// return CustomScrollView( /// // The "controller" and "primary" members should be left
/// // The "controller" and "primary" members should be left /// // unset, so that the NestedScrollView can control this
/// // unset, so that the NestedScrollView can control this /// // inner scroll view.
/// // inner scroll view. /// // If the "controller" property is set, then this scroll
/// // If the "controller" property is set, then this scroll /// // view will not be associated with the NestedScrollView.
/// // view will not be associated with the NestedScrollView. /// // The PageStorageKey should be unique to this ScrollView;
/// // The PageStorageKey should be unique to this ScrollView; /// // it allows the list to remember its scroll position when
/// // it allows the list to remember its scroll position when /// // the tab view is not on the screen.
/// // the tab view is not on the screen. /// key: PageStorageKey<String>(name),
/// key: PageStorageKey<String>(name), /// slivers: <Widget>[
/// slivers: <Widget>[ /// SliverOverlapInjector(
/// SliverOverlapInjector( /// // This is the flip side of the SliverOverlapAbsorber
/// // This is the flip side of the SliverOverlapAbsorber /// // above.
/// // above. /// handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
/// handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), /// ),
/// ), /// SliverPadding(
/// SliverPadding( /// padding: const EdgeInsets.all(8.0),
/// padding: const EdgeInsets.all(8.0), /// // In this example, the inner scroll view has
/// // In this example, the inner scroll view has /// // fixed-height list items, hence the use of
/// // fixed-height list items, hence the use of /// // SliverFixedExtentList. However, one could use any
/// // SliverFixedExtentList. However, one could use any /// // sliver widget here, e.g. SliverList or SliverGrid.
/// // sliver widget here, e.g. SliverList or SliverGrid. /// sliver: SliverFixedExtentList(
/// sliver: SliverFixedExtentList( /// // The items in this example are fixed to 48 pixels
/// // The items in this example are fixed to 48 pixels /// // high. This matches the Material Design spec for
/// // high. This matches the Material Design spec for /// // ListTile widgets.
/// // ListTile widgets. /// itemExtent: 48.0,
/// itemExtent: 48.0, /// delegate: SliverChildBuilderDelegate(
/// delegate: SliverChildBuilderDelegate( /// (BuildContext context, int index) {
/// (BuildContext context, int index) { /// // This builder is called for each child.
/// // This builder is called for each child. /// // In this example, we just number each list item.
/// // In this example, we just number each list item. /// return ListTile(
/// return ListTile( /// title: Text('Item $index'),
/// title: Text('Item $index'), /// );
/// ); /// },
/// }, /// // The childCount of the SliverChildBuilderDelegate
/// // The childCount of the SliverChildBuilderDelegate /// // specifies how many children this inner list
/// // specifies how many children this inner list /// // has. In this example, each tab has a list of
/// // has. In this example, each tab has a list of /// // exactly 30 items, but this is arbitrary.
/// // exactly 30 items, but this is arbitrary. /// childCount: 30,
/// childCount: 30, /// ),
/// ), /// ),
/// ), /// ),
/// ), /// ],
/// ], /// );
/// ); /// },
/// }, /// ),
/// ), /// );
/// ); /// }).toList(),
/// }).toList(), /// ),
/// ), /// ),
/// ), /// ),
/// ); /// );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment