fix: more checklist multiline issues (#6229)

* fix: more checklist multiline issues

* chore: add comment

* chore: apply code style improvments
This commit is contained in:
Richard Shiue 2024-09-09 09:22:08 +08:00 committed by GitHub
parent 06c356c7a1
commit ec799afb7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 34 deletions

View File

@ -138,6 +138,10 @@ class _EndEditingTaskIntent extends Intent {
const _EndEditingTaskIntent();
}
class _UpdateTaskDescriptionIntent extends Intent {
const _UpdateTaskDescriptionIntent();
}
/// Represents an existing task
@visibleForTesting
class ChecklistItem extends StatefulWidget {
@ -175,7 +179,7 @@ class _ChecklistItemState extends State<ChecklistItem> {
control: !Platform.isMacOS,
): const _SelectTaskIntent(),
const SingleActivator(LogicalKeyboardKey.enter):
const _EndEditingTaskIntent(),
const _UpdateTaskDescriptionIntent(),
const SingleActivator(LogicalKeyboardKey.escape):
const _EndEditingTaskIntent(),
};
@ -282,6 +286,14 @@ class _ChecklistItemState extends State<ChecklistItem> {
return;
},
),
_UpdateTaskDescriptionIntent:
CallbackAction<_UpdateTaskDescriptionIntent>(
onInvoke: (_UpdateTaskDescriptionIntent intent) {
textFieldFocusNode.unfocus();
widget.onSubmitted?.call();
return;
},
),
_EndEditingTaskIntent: CallbackAction<_EndEditingTaskIntent>(
onInvoke: (_EndEditingTaskIntent intent) {
textFieldFocusNode.unfocus();
@ -315,6 +327,7 @@ class NewTaskItem extends StatefulWidget {
class _NewTaskItemState extends State<NewTaskItem> {
final _textEditingController = TextEditingController();
bool _isCreateButtonEnabled = false;
@override
void initState() {
@ -339,45 +352,46 @@ class _NewTaskItemState extends State<NewTaskItem> {
children: [
const HSpace(8),
Expanded(
child: TextField(
focusNode: widget.focusNode,
controller: _textEditingController,
style: Theme.of(context).textTheme.bodyMedium,
decoration: InputDecoration(
border: InputBorder.none,
isCollapsed: true,
contentPadding: const EdgeInsets.symmetric(
vertical: 6.0,
horizontal: 2.0,
),
hintText: LocaleKeys.grid_checklist_addNew.tr(),
),
onSubmitted: (taskDescription) {
if (taskDescription.isNotEmpty) {
context
.read<ChecklistCellBloc>()
.add(ChecklistCellEvent.createNewTask(taskDescription));
_textEditingController.clear();
}
widget.focusNode.requestFocus();
child: CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.enter): () =>
_createNewTask(context),
},
onChanged: (value) => setState(() {}),
child: TextField(
focusNode: widget.focusNode,
controller: _textEditingController,
style: Theme.of(context).textTheme.bodyMedium,
maxLines: null,
decoration: InputDecoration(
border: InputBorder.none,
isCollapsed: true,
contentPadding: const EdgeInsets.symmetric(
vertical: 6.0,
horizontal: 2.0,
),
hintText: LocaleKeys.grid_checklist_addNew.tr(),
),
onSubmitted: (_) => _createNewTask(context),
onChanged: (value) => setState(
() => _isCreateButtonEnabled =
_textEditingController.text.isNotEmpty,
),
),
),
),
FlowyTextButton(
LocaleKeys.grid_checklist_submitNewTask.tr(),
fontSize: 11,
fillColor: _textEditingController.text.isEmpty
? Theme.of(context).disabledColor
: Theme.of(context).colorScheme.primary,
hoverColor: _textEditingController.text.isEmpty
? Theme.of(context).disabledColor
: Theme.of(context).colorScheme.primaryContainer,
fillColor: _isCreateButtonEnabled
? Theme.of(context).colorScheme.primary
: Theme.of(context).disabledColor,
hoverColor: _isCreateButtonEnabled
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).disabledColor,
fontColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
onPressed: _textEditingController.text.isEmpty
? null
: () {
onPressed: _isCreateButtonEnabled
? () {
context.read<ChecklistCellBloc>().add(
ChecklistCellEvent.createNewTask(
_textEditingController.text,
@ -385,10 +399,22 @@ class _NewTaskItemState extends State<NewTaskItem> {
);
widget.focusNode.requestFocus();
_textEditingController.clear();
},
}
: null,
),
],
),
);
}
void _createNewTask(BuildContext context) {
final taskDescription = _textEditingController.text;
if (taskDescription.isNotEmpty) {
context
.read<ChecklistCellBloc>()
.add(ChecklistCellEvent.createNewTask(taskDescription));
_textEditingController.clear();
}
widget.focusNode.requestFocus();
}
}

View File

@ -142,7 +142,7 @@ SPEC CHECKSUMS:
HotKey: e96d8a2ddbf4591131e2bb3f54e69554d90cdca6
hotkey_manager: c32bf0bfe8f934b7bc17ab4ad5c4c142960b023c
irondash_engine_context: da62996ee25616d2f01bbeb85dc115d813359478
local_notifier: c6c371695f914641ab7bc8601944f7e358632d0b
local_notifier: e9506bc66fc70311e8bc7291fb70f743c081e4ff
package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
ReachabilitySwift: 7f151ff156cea1481a8411701195ac6a984f4979