Skip to content

Commit 04fe962

Browse files
authored
Merge pull request #686 from vrtdev/bugfix/677-swallow-duplicate-ids
Silently swallow duplicate ids
2 parents 9aac393 + d9e905a commit 04fe962

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/src/anchor.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,28 @@ import 'package:flutter/widgets.dart';
33
import 'package:flutter_html/src/styled_element.dart';
44

55
class AnchorKey extends GlobalKey {
6+
static final Set<AnchorKey> _registry = <AnchorKey>{};
7+
68
final Key parentKey;
79
final String id;
810

911
const AnchorKey._(this.parentKey, this.id) : super.constructor();
1012

1113
static AnchorKey? of(Key? parentKey, StyledElement? id) {
12-
return forId(parentKey, id?.elementId);
14+
final key = forId(parentKey, id?.elementId);
15+
if (key == null || _registry.contains(key)) {
16+
// Invalid id or already created a key with this id: silently ignore
17+
return null;
18+
}
19+
_registry.add(key);
20+
return key;
1321
}
1422

1523
static AnchorKey? forId(Key? parentKey, String? id) {
1624
if (parentKey == null || id == null || id.isEmpty || id == "[[No ID]]") {
1725
return null;
1826
}
27+
1928
return AnchorKey._(parentKey, id);
2029
}
2130

0 commit comments

Comments
 (0)