Skip to content

Commit d731f27

Browse files
authored
Fix faulty cache assertion, bump vg (#879)
* Fix faulty cache assertion, bump vg * fixes
1 parent c190052 commit d731f27

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# CHANGES
22

3+
## 2.0.3
4+
5+
- Require newer version of vector_graphics.
6+
- Fix bug in cache that incorrectly fired assert.
7+
38
## 2.0.2
49

5-
- Consume newer version of vector_graphics with multiple fixes around
10+
- Require newer version of vector_graphics with multiple fixes around
611
inheritence, patterns, and currentColor handling.
712

813
## 2.0.1

analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ linter:
120120
- prefer_const_literals_to_create_immutables
121121
# - prefer_constructors_over_static_methods # not yet tested
122122
- prefer_contains
123-
- prefer_equal_for_default_values
124123
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
125124
- prefer_final_fields
126125
- prefer_final_locals

lib/src/cache.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class Cache {
8787
pendingResult.then((ByteData data) {
8888
_pending.remove(key);
8989
_add(key, data);
90-
9190
result = data; // in case it was a synchronous future.
9291
});
9392
}
@@ -101,7 +100,7 @@ class Cache {
101100

102101
void _add(Object key, ByteData result) {
103102
if (maximumSize > 0) {
104-
assert(_cache.length < maximumSize);
103+
assert(_cache.containsKey(key) || _cache.length < maximumSize);
105104
_cache[key] = result;
106105
}
107106
assert(_cache.length <= maximumSize);

pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: flutter_svg
22
description: An SVG rendering and widget library for Flutter, which allows painting and displaying Scalable Vector Graphics 1.1 files.
33
repository: https://github.com/dnfield/flutter_svg
44
issue_tracker: https://github.com/dnfield/flutter_svg/issues
5-
version: 2.0.2
5+
version: 2.0.3
66

77
dependencies:
88
flutter:
99
sdk: flutter
10-
vector_graphics: ^1.1.0
11-
vector_graphics_codec: ^1.1.0
12-
vector_graphics_compiler: ^1.1.0
10+
vector_graphics: ^1.1.3
11+
vector_graphics_codec: ^1.1.3
12+
vector_graphics_compiler: ^1.1.3
1313

1414
dev_dependencies:
1515
flutter_test:

test/cache_test.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:async';
2-
import 'dart:typed_data';
32

3+
import 'package:flutter/foundation.dart';
44
import 'package:flutter_svg/src/cache.dart';
55
import 'package:flutter_test/flutter_test.dart';
66

@@ -77,4 +77,32 @@ void main() {
7777
expect(cache.evict(2), false);
7878
expect(cache.evict(3), true);
7979
});
80+
81+
test('Adding beyond max with synchronous futures', () async {
82+
final Cache cache = Cache();
83+
cache.maximumSize = 2;
84+
final Future<ByteData> completerA =
85+
SynchronousFuture<ByteData>(ByteData(1));
86+
final Future<ByteData> completerB =
87+
SynchronousFuture<ByteData>(ByteData(2));
88+
final Future<ByteData> completerC =
89+
SynchronousFuture<ByteData>(ByteData(3));
90+
91+
expect(cache.count, 0);
92+
93+
cache.putIfAbsent(1, () => completerA);
94+
expect(cache.count, 1);
95+
96+
cache.putIfAbsent(2, () => completerB);
97+
expect(cache.count, 2);
98+
99+
cache.putIfAbsent(2, () => completerB);
100+
expect(cache.count, 2);
101+
102+
cache.putIfAbsent(3, () => completerC);
103+
expect(cache.count, 2);
104+
105+
cache.putIfAbsent(2, () => completerB);
106+
expect(cache.count, 2);
107+
});
80108
}

0 commit comments

Comments
 (0)