Skip to content

Commit 67feab1

Browse files
committed
Fix to ListMultimapBuilder.[].
1 parent 8162c48 commit 67feab1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 4.2.2 (unreleased)
4+
5+
- Bug fix: `ListMultimapBuilder.[]` no longer ignores modifications under some
6+
circumstances.
7+
38
## 4.2.1
49

510
- Bug fix: `ListBuilder` `first` and `last` setters can no longer modify the

lib/src/list_multimap/list_multimap_builder.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ class ListMultimapBuilder<K, V> {
166166
}
167167

168168
/// As [ListMultimap], but results are [ListBuilder]s.
169-
ListBuilder<V> operator [](Object key) =>
170-
key is K ? _getValuesBuilder(key) : new ListBuilder<V>();
169+
ListBuilder<V> operator [](Object key) {
170+
_makeWriteableCopy();
171+
return key is K ? _getValuesBuilder(key) : new ListBuilder<V>();
172+
}
171173

172174
// Internal.
173175

test/list_multimap/list_multimap_builder_test.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ void main() {
421421
{});
422422
});
423423

424-
test('has a method like ListMultimap[]', () {
424+
test('has a method like ListMultimap[] which can be used to read values',
425+
() {
425426
expect(
426427
new BuiltListMultimap<int, String>({
427428
1: ['1'],
@@ -437,5 +438,12 @@ void main() {
437438
}).toBuilder()[4].build().toList(),
438439
[]);
439440
});
441+
442+
test('has a method like ListMultimap[] which can be used to write values',
443+
() {
444+
var builder = BuiltListMultimap<int, String>().toBuilder();
445+
builder[1].add('1');
446+
expect(builder.build()[1], ['1']);
447+
});
440448
});
441449
}

0 commit comments

Comments
 (0)