From 698e7418518e42efd0fc40cb631719d5600bd6d6 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 30 Jan 2020 19:26:58 +0100 Subject: [PATCH] TodoEditor: Only show remove buttons when that item has focus Looks less cluttered. --- lib/editors/todo_editor.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/editors/todo_editor.dart b/lib/editors/todo_editor.dart index 62bcbba6..d72a0b39 100644 --- a/lib/editors/todo_editor.dart +++ b/lib/editors/todo_editor.dart @@ -170,11 +170,15 @@ class TodoItemTile extends StatefulWidget { class _TodoItemTileState extends State { TextEditingController _textController; + FocusNode _focusNode = FocusNode(); @override void initState() { super.initState(); _textController = TextEditingController(text: widget.todo.body); + _focusNode.addListener(() { + setState(() {}); + }); } @override @@ -182,6 +186,7 @@ class _TodoItemTileState extends State { var style = Theme.of(context).textTheme.subhead; var editor = TextField( + focusNode: _focusNode, keyboardType: TextInputType.text, maxLines: 1, style: style, @@ -194,6 +199,7 @@ class _TodoItemTileState extends State { ); return ListTile( + dense: true, leading: Row( children: [ Container(height: 24.0, width: 24.0, child: Icon(Icons.reorder)), @@ -205,11 +211,12 @@ class _TodoItemTileState extends State { mainAxisSize: MainAxisSize.min, ), title: editor, - trailing: IconButton( - icon: Icon(Icons.cancel), - onPressed: widget.todoRemoved, - ), - dense: true, + trailing: _focusNode.hasFocus + ? IconButton( + icon: Icon(Icons.cancel), + onPressed: widget.todoRemoved, + ) + : null, ); } } @@ -217,4 +224,4 @@ class _TodoItemTileState extends State { // FIXME: The body needs to be scrollable // FIXME: Add a new todo button // FIXME: Fix padding issue with todo items -// FIXME: Only show 'x' when active +// FIXME: When removing an item the focus should jump to the next/prev in line