mirror of
https://github.com/flutter/flutter
synced 2024-07-16 10:29:14 +00:00
make DevFSContent descendants immutable (#144664)
`DevFSBytesContent` (and it's descendant `DevFSStringContent`) have setters that change the underlying content. These are unused outside of tests, so this PR removes them. Amongst other things, this could help me refactor https://github.com/flutter/flutter/pull/144660 into something that has fewer pitfalls. This is purely a refactoring.
This commit is contained in:
parent
2ebd7f0d55
commit
cc33f44e41
|
@ -153,19 +153,12 @@ class DevFSFileContent extends DevFSContent {
|
|||
class DevFSByteContent extends DevFSContent {
|
||||
DevFSByteContent(this._bytes);
|
||||
|
||||
List<int> _bytes;
|
||||
|
||||
final List<int> _bytes;
|
||||
final DateTime _creationTime = DateTime.now();
|
||||
bool _isModified = true;
|
||||
DateTime _modificationTime = DateTime.now();
|
||||
|
||||
List<int> get bytes => _bytes;
|
||||
|
||||
set bytes(List<int> value) {
|
||||
_bytes = value;
|
||||
_isModified = true;
|
||||
_modificationTime = DateTime.now();
|
||||
}
|
||||
|
||||
/// Return true only once so that the content is written to the device only once.
|
||||
@override
|
||||
bool get isModified {
|
||||
|
@ -176,7 +169,7 @@ class DevFSByteContent extends DevFSContent {
|
|||
|
||||
@override
|
||||
bool isModifiedAfter(DateTime time) {
|
||||
return _modificationTime.isAfter(time);
|
||||
return _creationTime.isAfter(time);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -196,19 +189,9 @@ class DevFSStringContent extends DevFSByteContent {
|
|||
: _string = string,
|
||||
super(utf8.encode(string));
|
||||
|
||||
String _string;
|
||||
final String _string;
|
||||
|
||||
String get string => _string;
|
||||
|
||||
set string(String value) {
|
||||
_string = value;
|
||||
super.bytes = utf8.encode(_string);
|
||||
}
|
||||
|
||||
@override
|
||||
set bytes(List<int> value) {
|
||||
string = utf8.decode(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// A string compressing DevFSContent.
|
||||
|
@ -233,7 +216,7 @@ class DevFSStringCompressingBytesContent extends DevFSContent {
|
|||
|
||||
final String _string;
|
||||
final ZLibEncoder _compressor;
|
||||
final DateTime _modificationTime = DateTime.now();
|
||||
final DateTime _creationTime = DateTime.now();
|
||||
|
||||
bool _isModified = true;
|
||||
|
||||
|
@ -249,7 +232,7 @@ class DevFSStringCompressingBytesContent extends DevFSContent {
|
|||
|
||||
@override
|
||||
bool isModifiedAfter(DateTime time) {
|
||||
return _modificationTime.isAfter(time);
|
||||
return _creationTime.isAfter(time);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -67,10 +67,6 @@ void main() {
|
|||
expect(content.bytes, orderedEquals(<int>[4, 5, 6]));
|
||||
expect(content.isModified, isTrue);
|
||||
expect(content.isModified, isFalse);
|
||||
content.bytes = <int>[7, 8, 9, 2];
|
||||
expect(content.bytes, orderedEquals(<int>[7, 8, 9, 2]));
|
||||
expect(content.isModified, isTrue);
|
||||
expect(content.isModified, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('DevFSStringContent', () {
|
||||
|
@ -80,16 +76,6 @@ void main() {
|
|||
expect(content.bytes, orderedEquals(utf8.encode('some string')));
|
||||
expect(content.isModified, isTrue);
|
||||
expect(content.isModified, isFalse);
|
||||
content.string = 'another string';
|
||||
expect(content.string, 'another string');
|
||||
expect(content.bytes, orderedEquals(utf8.encode('another string')));
|
||||
expect(content.isModified, isTrue);
|
||||
expect(content.isModified, isFalse);
|
||||
content.bytes = utf8.encode('foo bar');
|
||||
expect(content.string, 'foo bar');
|
||||
expect(content.bytes, orderedEquals(utf8.encode('foo bar')));
|
||||
expect(content.isModified, isTrue);
|
||||
expect(content.isModified, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('DevFSFileContent', () async {
|
||||
|
|
Loading…
Reference in a new issue