Skip to content

Error type 'Null' is not a subtype of type '_Location' of 'value' when using tear-off constructor and enabling Track widget rebuilds from Devtools #118368

@30eggis

Description

@30eggis

Hi, i'm facing this error.

environment is :

IOS/Android
Real Device / Emulators

doctor

[✓] Flutter (Channel stable, 3.3.10, on macOS 13.0.1 22A400 darwin-arm
(Rosetta), locale ko-KR)
• Flutter version 3.3.10 on channel stable at /Users/ted/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision https://github.com/flutter/flutter/commit/135454af32477f815a7525073027a3ff9eff1bfd (4 weeks ago), 2022-12-15 07:36:55 -0800
• Engine revision 3316dd8728
• Dart version 2.18.6
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/ted/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• ANDROID_HOME = /Users/ted/Library/Android/sdk
• ANDROID_SDK_ROOT = /Users/ted/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.74.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

Scanning for devices is taking a long time...[✓] Connected device (4 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 •
Android 13 (API 33) (emulator)
• iPhone SE (3rd generation) (mobile) • 111BB95E-72C8-463E-AECA-0D28AB22FB9E • ios •
com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
• macOS (desktop) • macos • darwin-arm64 •
macOS 13.0.1 22A400 darwin-arm (Rosetta)
• Chrome (web) • chrome • web-javascript •
Google Chrome 108.0.5359.124

[✓] HTTP Host Availability
• All required HTTP hosts are available

• No issues found!

And i track inner flutter code, and i found weak null safety.

Error code.

======== Exception caught by widgets library =======================================================
The following _TypeError was thrown while rebuilding dirty elements:
type 'Null' is not a subtype of type '_Location' of 'value'

The relevant error-causing widget was:
MediaQuery MediaQuery:file:///Users/ted/project/mobile_app/lib/main.dart:141:36
When the exception was thrown, this was the stack:
#0 List.add (dart:core-patch/growable_array.dart)
https://github.com/flutter/flutter/pull/1 _toLocationId (package:flutter/src/widgets/widget_inspector.dart:3248:14)
https://github.com/flutter/flutter/pull/2 _ElementLocationStatsTracker.add (package:flutter/src/widgets/widget_inspector.dart:2158:20)
https://github.com/flutter/flutter/pull/3 WidgetInspectorService._onRebuildWidget (package:flutter/src/widgets/widget_inspector.dart:2034:19)
https://github.com/flutter/flutter/issues/4 Element.rebuild. (package:flutter/src/widgets/framework.dart:4585:34)
https://github.com/flutter/flutter/issues/5 Element.rebuild (package:flutter/src/widgets/framework.dart:4595:6)
https://github.com/flutter/flutter/issues/6 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:19)
https://github.com/flutter/flutter/issues/7 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
https://github.com/flutter/flutter/pull/8 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:378:5)
https://github.com/flutter/flutter/issues/9 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
https://github.com/flutter/flutter/pull/10 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
https://github.com/flutter/flutter/pull/11 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1015:5)
https://github.com/flutter/flutter/issues/12 _invoke (dart:ui/hooks.dart:148:13)
https://github.com/flutter/flutter/pull/13 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
https://github.com/flutter/flutter/pull/14 _drawFrame (dart:ui/hooks.dart:115:31)
The element being rebuilt at the time was index 120 of 430: HomeScreen-[<'HomeScreen'>]
dirty
dependencies: [MediaQuery]
state: _HomeScreenState#b4d12

=========

i think weak null safety to below code :

File name : widget_inspector.dart
search keyword : _toLocationId

"_toLocationId" method called from 2 point.
called on method "add" and on method "additionalNodeProperties"

in "additionalNodeProperties" case is null safety, because 'creationLocation' variable should not "null"

  @override
  Map<String, Object?> additionalNodeProperties(DiagnosticsNode node) {
    final Map<String, Object?> result = <String, Object?>{};
    final Object? value = node.value;
    if (_interactive) {
      result['objectId'] = service.toId(node, groupName!);
      result['valueId'] = service.toId(value, groupName!);
    }
    if (summaryTree) {
      result['summaryTree'] = true;
    }
    final _Location? creationLocation = _getCreationLocation(value);
    if (creationLocation != null) {
      result['locationId'] = _toLocationId(creationLocation);
    ...

but "add" case is not null safety, 'location' variable is no guard of null

  void add(Element element) {
    final Object widget = element.widget;
    if (widget is! _HasCreationLocation) {
      return;
    }
    final _HasCreationLocation creationLocationSource = widget;
    final _Location location = creationLocationSource._location;
    final int id = _toLocationId(location);
    ...

also, in '_toLocationId()' method is no protect from 'null'

int _toLocationId(_Location location) {
  int? id = _locationToId[location];
  if (id != null) {
    return id;
  }
  id = _locations.length;
  _locations.add(location);
  _locationToId[location] = id;
  return id;
}

please check this. Thank you

p/s : sorry to my terrible english

Metadata

Metadata

Labels

P1High-priority issues at the top of the work lista: devtoolsDevTools related - suite of performance and debugging toolsc: crashStack traces logged to the consolefound in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versiontoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions