Skip to content

Commit 9718a37

Browse files
committed
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
1 parent cfc6c9a commit 9718a37

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// ignore_for_file: use_build_context_synchronously
22
import 'dart:developer';
3+
import 'dart:ffi';
34
import 'dart:io';
45

56
import 'package:flutter/material.dart';
@@ -526,13 +527,19 @@ class AddTaskBottomSheet extends StatelessWidget {
526527
void addTag(String tag) {
527528
if (tag.isNotEmpty) {
528529
String trimmedString = tag.trim();
529-
trimmedString.split(" ").forEach((v) {
530-
homeController.tags.add(v);
531-
});
530+
List<String> tags = trimmedString.split(" ");
531+
for(tag in tags){
532+
if(checkTagIfExists(tag)) {
533+
removeTag(tag);
534+
}
535+
homeController.tags.add(tag);
536+
}
532537
homeController.tagcontroller.text = '';
533538
}
534539
}
535-
540+
bool checkTagIfExists(String tag){
541+
return homeController.tags.contains(tag);
542+
}
536543
void removeTag(String tag) {
537544
homeController.tags.remove(tag);
538545
}

0 commit comments

Comments
 (0)