Unverified Commit c4ffbb5e authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Update to ListView Sample Code in API Docs (#29072)

* Updated ListView Sample code with more examples for different constructors and also to match asset diagrams.

* Fixed MIA semicolons.

* Code cleanup.

* Added context for ListView.builder example.

* Analyzer does not like const and static usages.

* Replaced the const declarations with final. The analyzer does not like the use of const here, at all.

* Fixed parameterized declarations.
parent 816ae4b1
...@@ -604,17 +604,76 @@ abstract class BoxScrollView extends ScrollView { ...@@ -604,17 +604,76 @@ abstract class BoxScrollView extends ScrollView {
/// padding. To avoid this behavior, override with a zero [padding] property. /// padding. To avoid this behavior, override with a zero [padding] property.
/// ///
/// {@tool sample} /// {@tool sample}
/// This example uses the default constructor for [ListView] which takes an
/// explicit [List<Widget>] of children. This [ListView]'s children are made up
/// of [Container]s with [Text].
/// ///
/// An infinite list of children: /// ```dart
/// ListView(
/// padding: const EdgeInsets.all(8.0),
/// children: <Widget>[
/// Container(
/// height: 50,
/// color: Colors.amber[600],
/// child: const Center(child: Text('Entry A')),
/// ),
/// Container(
/// height: 50,
/// color: Colors.amber[500],
/// child: const Center(child: Text('Entry B')),
/// ),
/// Container(
/// height: 50,
/// color: Colors.amber[100],
/// child: const Center(child: Text('Entry C')),
/// ),
/// ],
/// )
/// ```
/// {@end-tool}
/// {@tool sample}
/// This example mirrors the previous one, creating the same list using the
/// [ListView.builder] constructor. Using the [IndexedWidgetBuilder], children
/// are built lazily and can be infinite in number.
/// ///
/// ```dart /// ```dart
/// final List<String> entries = <String>['A', 'B', 'C'];
/// final List<int> colorCodes = <int>[600, 500, 100];
///
/// ListView.builder( /// ListView.builder(
/// padding: EdgeInsets.all(8.0), /// padding: const EdgeInsets.all(8.0),
/// itemExtent: 20.0, /// itemCount: entries.length,
/// itemBuilder: (BuildContext context, int index) {
/// return Container(
/// height: 50,
/// color: Colors.amber[colorCodes[index]],
/// child: Center(child: Text('Entry ${entries[index]}')),
/// );
/// }
/// );
/// ```
/// {@end-tool}
/// {@tool sample}
/// This example continues to build from our the previous ones, creating a
/// similar list using [ListView.separated]. Here, a [Divider] is used as a
/// separator.
///
/// ```dart
/// final List<String> entries = <String>['A', 'B', 'C'];
/// final List<int> colorCodes = <int>[600, 500, 100];
///
/// ListView.separated(
/// padding: const EdgeInsets.all(8.0),
/// itemCount: entries.length,
/// itemBuilder: (BuildContext context, int index) { /// itemBuilder: (BuildContext context, int index) {
/// return Text('entry $index'); /// return Container(
/// height: 50,
/// color: Colors.amber[colorCodes[index]],
/// child: Center(child: Text('Entry ${entries[index]}')),
/// );
/// }, /// },
/// ) /// separatorBuilder: (BuildContext context, int index) => const Divider(),
/// );
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
......
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