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.
This commit is contained in:
parent
9ee6763a66
commit
8568eda15b
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user