From 8328b56ef37c511097545f24a054b6abe7631b0b Mon Sep 17 00:00:00 2001 From: Abdullah Deshmukh Date: Mon, 2 Nov 2020 19:18:03 +0530 Subject: [PATCH] AdoptAWidget: Dismissible (#69535) --- .../flutter/lib/src/widgets/dismissible.dart | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/flutter/lib/src/widgets/dismissible.dart b/packages/flutter/lib/src/widgets/dismissible.dart index 92eec7f8f9..673a22cb69 100644 --- a/packages/flutter/lib/src/widgets/dismissible.dart +++ b/packages/flutter/lib/src/widgets/dismissible.dart @@ -62,6 +62,41 @@ enum DismissDirection { /// /// {@youtube 560 315 https://www.youtube.com/watch?v=iEMgjrfuc58} /// +/// {@tool dartpad --template=stateful_widget_scaffold} +/// +/// This sample shows how you can use the [Dismissible] widget to +/// remove list items using swipe gestures. +/// +/// ```dart +/// List items = List.generate(100, (index) => index); +/// +/// Widget build(BuildContext context) { +/// return ListView.builder( +/// itemCount: items.length, +/// padding: const EdgeInsets.symmetric(vertical: 16), +/// itemBuilder: (BuildContext context, int index) { +/// return Dismissible( +/// child: ListTile( +/// title: Text( +/// 'Item ${items[index]}', +/// ), +/// ), +/// background: Container( +/// color: Colors.green, +/// ), +/// key: ValueKey(items[index]), +/// onDismissed: (DismissDirection direction) { +/// setState(() { +/// items.remove(index); +/// }); +/// }, +/// ); +/// }, +/// ); +/// } +/// ``` +/// {@end-tool} +/// /// Backgrounds can be used to implement the "leave-behind" idiom. If a background /// is specified it is stacked behind the Dismissible's child and is exposed when /// the child moves.