Unverified Commit fdb16cd7 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Cast config values to dynamic values instead of Object (#80011)

parent 3e5f620a
...@@ -62,7 +62,7 @@ class Config { ...@@ -62,7 +62,7 @@ class Config {
} }
try { try {
ErrorHandlingFileSystem.noExitOnFailure(() { ErrorHandlingFileSystem.noExitOnFailure(() {
_values = castStringKeyedMap(json.decode(_file.readAsStringSync())) as Map<String, Object>? ?? <String, Object>{}; _values = castStringKeyedMap(json.decode(_file.readAsStringSync())) ?? <String, Object>{};
}); });
} on FormatException { } on FormatException {
_logger _logger
...@@ -110,7 +110,7 @@ class Config { ...@@ -110,7 +110,7 @@ class Config {
String get configPath => _file.path; String get configPath => _file.path;
Map<String, Object> _values = <String, Object>{}; Map<String, dynamic> _values = <String, Object>{};
Iterable<String> get keys => _values.keys; Iterable<String> get keys => _values.keys;
......
...@@ -23,9 +23,9 @@ class FileStorage { ...@@ -23,9 +23,9 @@ class FileStorage {
throw Exception('File storage format invalid'); throw Exception('File storage format invalid');
} }
final int version = json['version'] as int; 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>[ 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); return FileStorage(version, cachedFiles);
} }
...@@ -48,7 +48,7 @@ class FileStorage { ...@@ -48,7 +48,7 @@ class FileStorage {
class _FileHash { class _FileHash {
_FileHash(this.path, this.hash); _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')) { if (!json.containsKey('path') || !json.containsKey('hash')) {
throw Exception('File storage format invalid'); throw Exception('File storage format invalid');
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
...@@ -78,7 +76,7 @@ void main() { ...@@ -78,7 +76,7 @@ void main() {
fileCache.initialize(); fileCache.initialize();
fileCache.diffFileList(<File>[file]); fileCache.diffFileList(<File>[file]);
fileCache.persist(); fileCache.persist();
final String currentHash = fileCache.currentAssetKeys[file.path]; final String? currentHash = fileCache.currentAssetKeys[file.path];
final Uint8List buffer = cacheFile final Uint8List buffer = cacheFile
.readAsBytesSync(); .readAsBytesSync();
FileStorage fileStorage = FileStorage.fromBuffer(buffer); FileStorage fileStorage = FileStorage.fromBuffer(buffer);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/config.dart'; import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/error_handling_io.dart'; import 'package:flutter_tools/src/base/error_handling_io.dart';
...@@ -16,9 +14,9 @@ import 'package:test/fake.dart'; ...@@ -16,9 +14,9 @@ import 'package:test/fake.dart';
import '../src/common.dart'; import '../src/common.dart';
void main() { void main() {
Config config; late Config config;
MemoryFileSystem memoryFileSystem; late MemoryFileSystem memoryFileSystem;
FakePlatform fakePlatform; late FakePlatform fakePlatform;
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
...@@ -35,6 +33,7 @@ void main() { ...@@ -35,6 +33,7 @@ void main() {
platform: fakePlatform, platform: fakePlatform,
); );
}); });
testWithoutContext('Config get set value', () async { testWithoutContext('Config get set value', () async {
expect(config.getValue('foo'), null); expect(config.getValue('foo'), null);
config.setValue('foo', 'bar'); config.setValue('foo', 'bar');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment