Cast config values to dynamic values instead of Object (#80011)
This commit is contained in:
@@ -62,7 +62,7 @@ class Config {
|
||||
}
|
||||
try {
|
||||
ErrorHandlingFileSystem.noExitOnFailure(() {
|
||||
_values = castStringKeyedMap(json.decode(_file.readAsStringSync())) as Map<String, Object>? ?? <String, Object>{};
|
||||
_values = castStringKeyedMap(json.decode(_file.readAsStringSync())) ?? <String, Object>{};
|
||||
});
|
||||
} on FormatException {
|
||||
_logger
|
||||
@@ -110,7 +110,7 @@ class Config {
|
||||
|
||||
String get configPath => _file.path;
|
||||
|
||||
Map<String, Object> _values = <String, Object>{};
|
||||
Map<String, dynamic> _values = <String, Object>{};
|
||||
|
||||
Iterable<String> get keys => _values.keys;
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ class FileStorage {
|
||||
throw Exception('File storage format invalid');
|
||||
}
|
||||
final int version = json['version'] as int;
|
||||
final List<Map<String, Object>> rawCachedFiles = (json['files'] as List<dynamic>).cast<Map<String, Object>>();
|
||||
final List<Map<String, dynamic>> rawCachedFiles = (json['files'] as List<dynamic>).cast<Map<String, dynamic>>();
|
||||
final List<_FileHash> cachedFiles = <_FileHash>[
|
||||
for (final Map<String, Object> rawFile in rawCachedFiles) _FileHash._fromJson(rawFile),
|
||||
for (final Map<String, dynamic> rawFile in rawCachedFiles) _FileHash._fromJson(rawFile),
|
||||
];
|
||||
return FileStorage(version, cachedFiles);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class FileStorage {
|
||||
class _FileHash {
|
||||
_FileHash(this.path, this.hash);
|
||||
|
||||
factory _FileHash._fromJson(Map<String, Object> json) {
|
||||
factory _FileHash._fromJson(Map<String, dynamic> json) {
|
||||
if (!json.containsKey('path') || !json.containsKey('hash')) {
|
||||
throw Exception('File storage format invalid');
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
@@ -78,7 +76,7 @@ void main() {
|
||||
fileCache.initialize();
|
||||
fileCache.diffFileList(<File>[file]);
|
||||
fileCache.persist();
|
||||
final String currentHash = fileCache.currentAssetKeys[file.path];
|
||||
final String? currentHash = fileCache.currentAssetKeys[file.path];
|
||||
final Uint8List buffer = cacheFile
|
||||
.readAsBytesSync();
|
||||
FileStorage fileStorage = FileStorage.fromBuffer(buffer);
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/config.dart';
|
||||
import 'package:flutter_tools/src/base/error_handling_io.dart';
|
||||
@@ -16,9 +14,9 @@ import 'package:test/fake.dart';
|
||||
import '../src/common.dart';
|
||||
|
||||
void main() {
|
||||
Config config;
|
||||
MemoryFileSystem memoryFileSystem;
|
||||
FakePlatform fakePlatform;
|
||||
late Config config;
|
||||
late MemoryFileSystem memoryFileSystem;
|
||||
late FakePlatform fakePlatform;
|
||||
|
||||
setUp(() {
|
||||
memoryFileSystem = MemoryFileSystem.test();
|
||||
@@ -35,6 +33,7 @@ void main() {
|
||||
platform: fakePlatform,
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('Config get set value', () async {
|
||||
expect(config.getValue('foo'), null);
|
||||
config.setValue('foo', 'bar');
|
||||
|
||||
Reference in New Issue
Block a user