Unverified Commit 8568eda1 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Added an empty list example to the ListView docs (#56394)

Added and example to the ListView docs that shows how to have a custom UI for an empty list.
parent 9ee6763a
......@@ -21,6 +21,9 @@ import 'scrollable.dart';
import 'sliver.dart';
import 'viewport.dart';
// Examples can assume:
// int itemCount;
/// A representation of how a [ScrollView] should dismiss the on-screen
/// keyboard.
enum ScrollViewKeyboardDismissBehavior {
......@@ -865,6 +868,36 @@ abstract class BoxScrollView extends ScrollView {
/// ```
/// {@end-tool}
///
/// ## Special handling for an empty list
///
/// A common design pattern is to have a custom UI for an empty list. The best
/// way to achieve this in Flutter is just conditionally replacing the
/// [ListView] at build time with whatever widgets you need to show for the
/// empty list state:
///
/// {@tool snippet}
///
/// Example of simple empty list interface:
///
/// ```dart
/// Widget build(BuildContext context) {
/// return Scaffold(
/// appBar: AppBar(title: const Text('Empty List Test')),
/// body: itemCount > 0
/// ? ListView.builder(
/// itemCount: itemCount,
/// itemBuilder: (BuildContext context, int index) {
/// return ListTile(
/// title: Text('Item ${index + 1}'),
/// );
/// },
/// )
/// : Center(child: const Text('No items')),
/// );
/// }
/// ```
/// {@end-tool}
///
/// See also:
///
/// * [SingleChildScrollView], which is a scrollable widget that has a single
......
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