Skip to content

Commit 760ac02

Browse files
authored
fix: trim and validate task name input for whitespace
PR #569
1 parent 8e2b1c5 commit 760ac02

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/app/modules/home/views/add_task_bottom_sheet_new.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AddTaskBottomSheet extends StatelessWidget {
9696
padding: const EdgeInsets.all(padding),
9797
child: TextFormField(
9898
controller: homeController.namecontroller,
99-
validator: (value) => value!.isEmpty
99+
validator: (value) => value!.trim().isEmpty
100100
? SentenceManager(
101101
currentLanguage:
102102
homeController.selectedLanguage.value)
@@ -317,7 +317,7 @@ class AddTaskBottomSheet extends StatelessWidget {
317317
if (homeController.formKey.currentState!.validate()) {
318318
debugPrint("tags ${homeController.tags}");
319319
var task = TaskForC(
320-
description: homeController.namecontroller.text,
320+
description: homeController.namecontroller.text.trim(),
321321
status: 'pending',
322322
priority: homeController.priority.value,
323323
entry: DateTime.now().toIso8601String(),
@@ -365,7 +365,7 @@ class AddTaskBottomSheet extends StatelessWidget {
365365
void onSaveButtonClicked(BuildContext context) async {
366366
if (homeController.formKey.currentState!.validate()) {
367367
try {
368-
var task = taskParser(homeController.namecontroller.text)
368+
var task = taskParser(homeController.namecontroller.text.trim())
369369
.rebuild((b) =>
370370
b..due = getDueDate(homeController.selectedDates)?.toUtc())
371371
.rebuild((p) => p..priority = homeController.priority.value)
@@ -451,7 +451,7 @@ class AddTaskBottomSheet extends StatelessWidget {
451451
if (homeController.formKey.currentState!.validate()) {
452452
try {
453453
await Replica.addTaskToReplica(HashMap<String, dynamic>.from({
454-
"description": homeController.namecontroller.text,
454+
"description": homeController.namecontroller.text.trim(),
455455
"due": getDueDate(homeController.selectedDates)?.toUtc(),
456456
"priority": homeController.priority.value,
457457
"project": homeController.projectcontroller.text != ""

lib/app/utils/taskfunctions/validate.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
void validateTaskDescription(String description) {
2-
if (description.isEmpty) {
2+
if (description.trim().isEmpty) {
33
throw FormatException(
4-
'Empty description will provoke a server error.',
4+
'Description cannot be empty or contain only spaces.',
55
description,
66
0,
77
);

0 commit comments

Comments
 (0)