From b3cfa785c4b43768175ca56729b1a39b0613d6de Mon Sep 17 00:00:00 2001 From: Leaf Petersen Date: Thu, 21 Dec 2017 13:39:03 -0800 Subject: [PATCH] Uncontroversial and backwards compatible 2.0 SDK fixes (#13723) Small code changes as part of moving the framework SDK forward to a 2.0 dev version. --- dev/benchmarks/microbenchmarks/lib/common.dart | 10 +++++----- dev/bots/test.dart | 9 ++++----- dev/devicelab/lib/tasks/gallery.dart | 8 ++++---- dev/devicelab/lib/tasks/perf_tests.dart | 9 ++++----- dev/integration_tests/flavors/lib/main.dart | 2 +- dev/tools/gen_date_localizations.dart | 2 +- examples/flutter_gallery/lib/gallery/app.dart | 14 ++++++-------- examples/platform_channel/lib/main.dart | 2 +- examples/platform_channel_swift/lib/main.dart | 2 +- examples/stocks/lib/stock_strings.dart | 2 +- packages/flutter/lib/src/widgets/binding.dart | 3 ++- packages/flutter/lib/src/widgets/table.dart | 11 ++++++----- .../test/semantics/semantics_service_test.dart | 3 ++- 13 files changed, 38 insertions(+), 39 deletions(-) diff --git a/dev/benchmarks/microbenchmarks/lib/common.dart b/dev/benchmarks/microbenchmarks/lib/common.dart index f34e403e57..ca058061f7 100644 --- a/dev/benchmarks/microbenchmarks/lib/common.dart +++ b/dev/benchmarks/microbenchmarks/lib/common.dart @@ -50,11 +50,11 @@ class BenchmarkResultPrinter { } String _printJson() { - return JSON.encode(new Map.fromIterable( - _results, - key: (_BenchmarkResult result) => result.name, - value: (_BenchmarkResult result) => result.value, - )); + final Map results = {}; + for (_BenchmarkResult result in _results) { + results[result.name] = result.value; + } + return JSON.encode(results); } String _printPlainText() { diff --git a/dev/bots/test.dart b/dev/bots/test.dart index ce5294fbb1..80fdf80eda 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -373,11 +373,10 @@ Future _verifyNoBadImports(String workingDirectory) async { ); } // Verify that the imports are well-ordered. - final Map> dependencyMap = new Map>.fromIterable( - directories, - key: (String directory) => directory, - value: (String directory) => _findDependencies(path.join(srcPath, directory), errors, checkForMeta: directory != 'foundation'), - ); + final Map> dependencyMap = >{}; + for (String directory in directories) { + dependencyMap[directory] = _findDependencies(path.join(srcPath, directory), errors, checkForMeta: directory != 'foundation'); + } for (String package in dependencyMap.keys) { if (dependencyMap[package].contains(package)) { errors.add( diff --git a/dev/devicelab/lib/tasks/gallery.dart b/dev/devicelab/lib/tasks/gallery.dart index 418ff3ab3b..e287f89070 100644 --- a/dev/devicelab/lib/tasks/gallery.dart +++ b/dev/devicelab/lib/tasks/gallery.dart @@ -53,10 +53,10 @@ class GalleryTransitionTest { final Map> original = JSON.decode(file( '${galleryDirectory.path}/build/transition_durations.timeline.json') .readAsStringSync()); - final Map> transitions = new Map>.fromIterable( - original.keys, - key: (String key) => key.replaceAll('/', ''), - value: (String key) => original[key]); + final Map> transitions = >{}; + for (String key in original.keys) { + transitions[key.replaceAll('/', '')] = original[key]; + } final Map summary = JSON.decode(file('${galleryDirectory.path}/build/transitions.timeline_summary.json').readAsStringSync()); diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index febc94fd4a..721b7c5ef0 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -240,11 +240,10 @@ class CompileTest { watch.stop(); final RegExp metricExpression = new RegExp(r'([a-zA-Z]+)\(CodeSize\)\: (\d+)'); - final Map metrics = new Map.fromIterable( - metricExpression.allMatches(compileLog), - key: (Match m) => _sdkNameToMetricName(m.group(1)), - value: (Match m) => int.parse(m.group(2)), - ); + final Map metrics = {}; + for (Match m in metricExpression.allMatches(compileLog)) { + metrics[_sdkNameToMetricName(m.group(1))] = int.parse(m.group(2)); + } metrics['aot_snapshot_compile_millis'] = watch.elapsedMilliseconds; return metrics; diff --git a/dev/integration_tests/flavors/lib/main.dart b/dev/integration_tests/flavors/lib/main.dart index 3cb45d2f70..716f4125c2 100644 --- a/dev/integration_tests/flavors/lib/main.dart +++ b/dev/integration_tests/flavors/lib/main.dart @@ -18,7 +18,7 @@ class _FlavorState extends State { @override void initState() { super.initState(); - const MethodChannel('flavor').invokeMethod('getFlavor').then((String flavor) { + const MethodChannel('flavor').invokeMethod('getFlavor').then((Object flavor) { setState(() { _flavor = flavor; }); diff --git a/dev/tools/gen_date_localizations.dart b/dev/tools/gen_date_localizations.dart index ad81532d4b..a7261b2410 100644 --- a/dev/tools/gen_date_localizations.dart +++ b/dev/tools/gen_date_localizations.dart @@ -125,7 +125,7 @@ String _jsonToMap(dynamic json) { if (json is Iterable) return 'const [${json.map(_jsonToMap).join(',')}]'; - if (json is Map) { + if (json is Map) { final StringBuffer buffer = new StringBuffer('const {'); json.forEach((String key, dynamic value) { buffer.writeln(_jsonToMapEntry(key, value)); diff --git a/examples/flutter_gallery/lib/gallery/app.dart b/examples/flutter_gallery/lib/gallery/app.dart index 1f2e4edf55..dd318c431d 100644 --- a/examples/flutter_gallery/lib/gallery/app.dart +++ b/examples/flutter_gallery/lib/gallery/app.dart @@ -149,17 +149,15 @@ class GalleryAppState extends State { ); } - final Map _kRoutes = - new Map.fromIterable( + final Map _kRoutes = {}; + for (GalleryItem item in kAllGalleryItems) { // For a different example of how to set up an application routing table // using named routes, consider the example in the Navigator class documentation: // https://docs.flutter.io/flutter/widgets/Navigator-class.html - kAllGalleryItems, - key: (GalleryItem item) => item.routeName, - value: (GalleryItem item) { - return (BuildContext context) => _applyScaleFactor(item.buildRoute(context)); - }, - ); + _kRoutes[item.routeName] = (BuildContext context) { + return _applyScaleFactor(item.buildRoute(context)); + }; + } return new MaterialApp( title: 'Flutter Gallery', diff --git a/examples/platform_channel/lib/main.dart b/examples/platform_channel/lib/main.dart index f258120c97..ffae0828e8 100644 --- a/examples/platform_channel/lib/main.dart +++ b/examples/platform_channel/lib/main.dart @@ -40,7 +40,7 @@ class _PlatformChannelState extends State { eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); } - void _onEvent(String event) { + void _onEvent(Object event) { setState(() { _chargingStatus = "Battery status: ${event == 'charging' ? '' : 'dis'}charging."; diff --git a/examples/platform_channel_swift/lib/main.dart b/examples/platform_channel_swift/lib/main.dart index f258120c97..ffae0828e8 100644 --- a/examples/platform_channel_swift/lib/main.dart +++ b/examples/platform_channel_swift/lib/main.dart @@ -40,7 +40,7 @@ class _PlatformChannelState extends State { eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); } - void _onEvent(String event) { + void _onEvent(Object event) { setState(() { _chargingStatus = "Battery status: ${event == 'charging' ? '' : 'dis'}charging."; diff --git a/examples/stocks/lib/stock_strings.dart b/examples/stocks/lib/stock_strings.dart index 0f84672d13..344db8a37e 100644 --- a/examples/stocks/lib/stock_strings.dart +++ b/examples/stocks/lib/stock_strings.dart @@ -19,7 +19,7 @@ class StockStrings { static Future load(Locale locale) { return initializeMessages(locale.toString()) - .then((Null _) { + .then((Object _) { return new StockStrings(locale); }); } diff --git a/packages/flutter/lib/src/widgets/binding.dart b/packages/flutter/lib/src/widgets/binding.dart index 3457dcf87f..cd34824673 100644 --- a/packages/flutter/lib/src/widgets/binding.dart +++ b/packages/flutter/lib/src/widgets/binding.dart @@ -459,7 +459,8 @@ abstract class WidgetsBinding extends BindingBase with SchedulerBinding, Gesture observer.didHaveMemoryPressure(); } - Future _handleSystemMessage(Map message) async { + Future _handleSystemMessage(Object systemMessage) async { + final Map message = systemMessage; final String type = message['type']; switch (type) { case 'memoryPressure': diff --git a/packages/flutter/lib/src/widgets/table.dart b/packages/flutter/lib/src/widgets/table.dart index 22f34252c4..22f00ab4f6 100644 --- a/packages/flutter/lib/src/widgets/table.dart +++ b/packages/flutter/lib/src/widgets/table.dart @@ -300,11 +300,12 @@ class _TableElement extends RenderObjectElement { void update(Table newWidget) { assert(!_debugWillReattachChildren); assert(() { _debugWillReattachChildren = true; return true; }()); - final Map> oldKeyedRows = new Map>.fromIterable( - _children.where((_TableElementRow row) => row.key != null), - key: (_TableElementRow row) => row.key, - value: (_TableElementRow row) => row.children - ); + final Map> oldKeyedRows = >{}; + for (_TableElementRow row in _children) { + if (row.key != null) { + oldKeyedRows[row.key] = row.children; + } + } final Iterator<_TableElementRow> oldUnkeyedRows = _children.where((_TableElementRow row) => row.key == null).iterator; final List<_TableElementRow> newChildren = <_TableElementRow>[]; final Set> taken = new Set>(); diff --git a/packages/flutter/test/semantics/semantics_service_test.dart b/packages/flutter/test/semantics/semantics_service_test.dart index aae4c38447..b96685b3d0 100644 --- a/packages/flutter/test/semantics/semantics_service_test.dart +++ b/packages/flutter/test/semantics/semantics_service_test.dart @@ -12,7 +12,8 @@ void main() { test('Semantic announcement', () async { final List> log = >[]; - SystemChannels.accessibility.setMockMessageHandler((Map message) async { + SystemChannels.accessibility.setMockMessageHandler((Object mockMessage) async { + final Map message = mockMessage; log.add(message); });