From a3bcaf226c01d17d0edab43c8635580f80c1b330 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Fri, 30 Apr 2021 21:09:14 -0700 Subject: [PATCH] Allow widget inspector's _Location.file to be null (#81588) Fixes https://github.com/flutter/flutter/issues/81587 --- .../lib/src/widgets/widget_inspector.dart | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index b96f9e3667..7d7571991e 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -1525,7 +1525,7 @@ mixin WidgetInspectorService { if (location == null || location.file == null) { return false; } - final String file = Uri.parse(location.file).path; + final String file = Uri.parse(location.file!).path; // By default check whether the creation location was within package:flutter. if (_pubRootDirectories == null) { @@ -2122,11 +2122,13 @@ class _ElementLocationStatsTracker { final Map> locationsJson = >{}; for (final _LocationCount entry in newLocations) { final _Location location = entry.location; - final List jsonForFile = locationsJson.putIfAbsent( - location.file, - () => [], - ); - jsonForFile..add(entry.id)..add(location.line)..add(location.column); + if (location.file != null) { + final List jsonForFile = locationsJson.putIfAbsent( + location.file!, + () => [], + ); + jsonForFile..add(entry.id)..add(location.line)..add(location.column); + } } json['newLocations'] = locationsJson; } @@ -2844,7 +2846,7 @@ class _Location { }); /// File path of the location. - final String file; + final String? file; /// 1-based line number. final int line; @@ -2880,7 +2882,9 @@ class _Location { if (name != null) { parts.add(name!); } - parts.add(file); + if (file != null) { + parts.add(file!); + } parts..add('$line')..add('$column'); return parts.join(':'); }