From 71fa85eca7e29119dd13494c3edca004b660c9db Mon Sep 17 00:00:00 2001 From: Shubham Ingale Date: Sun, 15 Dec 2024 16:03:11 +0530 Subject: [PATCH 1/4] feat: add tag to tags array immediately after input whitespace --- .../home/views/add_task_bottom_sheet.dart | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/app/modules/home/views/add_task_bottom_sheet.dart b/lib/app/modules/home/views/add_task_bottom_sheet.dart index d605068..00eb670 100644 --- a/lib/app/modules/home/views/add_task_bottom_sheet.dart +++ b/lib/app/modules/home/views/add_task_bottom_sheet.dart @@ -112,6 +112,13 @@ class AddTaskBottomSheet extends StatelessWidget { onFieldSubmitted: (tag) { addTag(tag.trim()); }, + onChanged: (value) { + String trimmedString = value.trim(); + if (value.endsWith(" ") && + trimmedString.split(' ').length == 1) { + addTag(trimmedString); + } + }, ), ), IconButton( @@ -158,9 +165,9 @@ class AddTaskBottomSheet extends StatelessWidget { ), validator: (name) => name != null && name.isEmpty ? SentenceManager( - currentLanguage: homeController.selectedLanguage.value) - .sentences - .addTaskFieldCannotBeEmpty + currentLanguage: homeController.selectedLanguage.value) + .sentences + .addTaskFieldCannotBeEmpty : null, ); @@ -400,9 +407,9 @@ class AddTaskBottomSheet extends StatelessWidget { TextButton( child: Text( SentenceManager( - currentLanguage: homeController.selectedLanguage.value) - .sentences - .addTaskCancel, + currentLanguage: homeController.selectedLanguage.value) + .sentences + .addTaskCancel, style: TextStyle( color: AppSettings.isDarkMode ? TaskWarriorColors.white @@ -425,8 +432,8 @@ class AddTaskBottomSheet extends StatelessWidget { child: Text( SentenceManager( currentLanguage: homeController.selectedLanguage.value) - .sentences - .addTaskAdd, + .sentences + .addTaskAdd, style: TextStyle( color: AppSettings.isDarkMode ? TaskWarriorColors.white @@ -472,8 +479,8 @@ class AddTaskBottomSheet extends StatelessWidget { content: Text( SentenceManager( currentLanguage: homeController.selectedLanguage.value) - .sentences - .addTaskTaskAddedSuccessfully, + .sentences + .addTaskTaskAddedSuccessfully, style: TextStyle( color: AppSettings.isDarkMode ? TaskWarriorColors.kprimaryTextColor From cfc6c9a76b20e9e12f393bd1301b1e6bdaa11993 Mon Sep 17 00:00:00 2001 From: Shubham Ingale Date: Sun, 15 Dec 2024 16:05:51 +0530 Subject: [PATCH 2/4] feat: split tag input by whitespaces to avoid whitespaces in each tag --- lib/app/modules/home/views/add_task_bottom_sheet.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/app/modules/home/views/add_task_bottom_sheet.dart b/lib/app/modules/home/views/add_task_bottom_sheet.dart index 00eb670..1949238 100644 --- a/lib/app/modules/home/views/add_task_bottom_sheet.dart +++ b/lib/app/modules/home/views/add_task_bottom_sheet.dart @@ -526,7 +526,9 @@ class AddTaskBottomSheet extends StatelessWidget { void addTag(String tag) { if (tag.isNotEmpty) { String trimmedString = tag.trim(); - homeController.tags.add(trimmedString); + trimmedString.split(" ").forEach((v) { + homeController.tags.add(v); + }); homeController.tagcontroller.text = ''; } } From 9718a37c71dd1d1173e828ebc115db16e4e12df8 Mon Sep 17 00:00:00 2001 From: Shubham Ingale Date: Sun, 15 Dec 2024 17:08:32 +0530 Subject: [PATCH 3/4] fix: remove tag if already exists in list and add again Problem: while adding task a tag can be added multiple times to fix this following bhavior will be followed: 1. delete tag from list if already exists 2. then add tag to list So that the current tag can be added at last to show latest added tag --- .../modules/home/views/add_task_bottom_sheet.dart | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/app/modules/home/views/add_task_bottom_sheet.dart b/lib/app/modules/home/views/add_task_bottom_sheet.dart index 1949238..a817390 100644 --- a/lib/app/modules/home/views/add_task_bottom_sheet.dart +++ b/lib/app/modules/home/views/add_task_bottom_sheet.dart @@ -1,5 +1,6 @@ // ignore_for_file: use_build_context_synchronously import 'dart:developer'; +import 'dart:ffi'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -526,13 +527,19 @@ class AddTaskBottomSheet extends StatelessWidget { void addTag(String tag) { if (tag.isNotEmpty) { String trimmedString = tag.trim(); - trimmedString.split(" ").forEach((v) { - homeController.tags.add(v); - }); + List tags = trimmedString.split(" "); + for(tag in tags){ + if(checkTagIfExists(tag)) { + removeTag(tag); + } + homeController.tags.add(tag); + } homeController.tagcontroller.text = ''; } } - + bool checkTagIfExists(String tag){ + return homeController.tags.contains(tag); + } void removeTag(String tag) { homeController.tags.remove(tag); } From b2e8e0e3ed338b242c7edcf57d4476b3f031b844 Mon Sep 17 00:00:00 2001 From: Shubham Ingale Date: Sun, 15 Dec 2024 17:32:34 +0530 Subject: [PATCH 4/4] fix: removed `dart:ffi` added by recent commit --- lib/app/modules/home/views/add_task_bottom_sheet.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/app/modules/home/views/add_task_bottom_sheet.dart b/lib/app/modules/home/views/add_task_bottom_sheet.dart index a817390..f1ba520 100644 --- a/lib/app/modules/home/views/add_task_bottom_sheet.dart +++ b/lib/app/modules/home/views/add_task_bottom_sheet.dart @@ -1,6 +1,5 @@ // ignore_for_file: use_build_context_synchronously import 'dart:developer'; -import 'dart:ffi'; import 'dart:io'; import 'package:flutter/material.dart';