Skip to content

Commit

Permalink
Make tasks deletable in example app (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitusortner authored May 17, 2019
1 parent e687aef commit 498356a
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ class TasksWidget extends StatelessWidget {
return ListView.builder(
itemCount: tasks.length,
itemBuilder: (_, index) {
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 16,
),
child: Text(tasks[index].message),
return ListCell(
task: tasks[index],
dao: dao,
);
},
);
Expand All @@ -73,8 +70,10 @@ class TasksWidget extends StatelessWidget {
),
TextField(
controller: _textEditingController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(8),
decoration: InputDecoration(
fillColor: Theme.of(context).inputDecorationTheme.fillColor,
filled: true,
contentPadding: const EdgeInsets.all(16),
border: InputBorder.none,
hintText: 'Type task here',
),
Expand All @@ -91,3 +90,36 @@ class TasksWidget extends StatelessWidget {
);
}
}

class ListCell extends StatelessWidget {
const ListCell({
Key key,
@required this.task,
@required this.dao,
}) : super(key: key);

final Task task;
final TaskDao dao;

@override
Widget build(BuildContext context) {
return Dismissible(
key: Key('${task.hashCode}'),
background: Container(color: Colors.red),
direction: DismissDirection.endToStart,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 16,
),
child: Text(task.message),
),
onDismissed: (_) async {
await dao.deleteTask(task);
Scaffold.of(context).showSnackBar(
SnackBar(content: const Text('Removed task')),
);
},
);
}
}

0 comments on commit 498356a

Please sign in to comment.