From a68f3f57d69d73ab79a5804fb53263e45db23bbf Mon Sep 17 00:00:00 2001 From: Abdullah Deshmukh Date: Wed, 11 Aug 2021 08:16:16 +0530 Subject: [PATCH] [linting_tool] Stop duplication of rules in the same profile (#870) --- .../linting_tool/lib/model/profiles_store.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/experimental/linting_tool/lib/model/profiles_store.dart b/experimental/linting_tool/lib/model/profiles_store.dart index 7d6155b0b..cc00dc1d3 100644 --- a/experimental/linting_tool/lib/model/profiles_store.dart +++ b/experimental/linting_tool/lib/model/profiles_store.dart @@ -59,8 +59,15 @@ class ProfilesStore extends ChangeNotifier { } Future addToExistingProfile(RulesProfile profile, Rule rule) async { - RulesProfile newProfile = - RulesProfile(name: profile.name, rules: profile.rules..add(rule)); + // TODO(abd99): Consider refactoring to LinkedHashSet/SplayTreeSet to avoid + // duplication automatically. + // ref: https://github.com/flutter/samples/pull/870#discussion_r685666792 + var rules = profile.rules; + if (!rules.contains(rule)) { + rules.add(rule); + } + + RulesProfile newProfile = RulesProfile(name: profile.name, rules: rules); await HiveService.updateBox(profile, newProfile, _boxName);