类型 'String' 不是预期类型 'int' 的子类型

Type 'String' is not a subtype of expected type 'int'

搜索结果时出现此错误。现在花了几个小时进行调试,但无法发现问题所在。尝试将 id 分配给 Place 对象时,一定是一些反序列化问题。但我不是 JavaScript 专家(这就是我想使用 dart 的原因)。但是当然文件会被转换成 JavaScript,然后 Developer Tools 调试器会引用生成的 JS 文件。

奇怪的是它与我的模拟后端一起工作。但它不适用于 Aqueduct 后端。 Aqueduct 本身提供正确的输出。

[{"id":1,"name":"Easyhotel"},{"id":2,"name":"Hotel Greulich"}]

正在获取所有对象的列表。好像只和搜索方式有关

如有任何提示,我们将不胜感激。

版本

Dart VM 版本:2.0.0-dev.68.0(7 月 10 日星期二 14:47:26 2018 +0200)"macos_x64"

pubspec.yaml

name: places
description: Cool Places
version: 0.0.1

environment:
  sdk: '>=2.0.0-dev.66.0 <2.0.0'

dependencies:
  angular: ^5.0.0-beta
  angular_forms: ^2.0.0-beta
  angular_router: ^2.0.0-alpha
  http: ^0.11.0            
  stream_transform: ^0.0.6
  angular_components: ^0.9.0-alpha+15

dev_dependencies:
  sass_builder: ^2.0.0
  angular_test: ^2.0.0-beta
  build_runner: ^0.9.0
  build_test: ^0.10.2
  build_web_compilers: ^0.4.0
  test: ^1.0.0

place_search_service.dart

import 'dart:async';
import 'dart:convert';
import 'package:angular/angular.dart';
import 'package:http/http.dart';

import 'package:places/src/place/place.dart';

@Injectable()
class PlaceSearchService {
  final Client _http;

  PlaceSearchService(this._http);

  Future<List<Place>> search(String term) async {
    try {
      final response = await _http.get('http://localhost:8888/places?name=$term');
      return (_extractData(response) as List)
          .map((json) => new Place.fromJson(json))
          .toList();
    } catch (e) {
      throw _handleError(e);
    }
  }

  dynamic _extractData(Response resp) => json.decode(resp.body)['data'];

  Exception _handleError(dynamic e) {
    print(e); // for demo purposes only
    return new Exception('Server error; cause: $e');
  }
}

place.dart

class Place {
  final int id;
  String name;

  Place(this.id, this.name);

  factory Place.fromJson(Map<String, dynamic> place) =>
      new Place(_toInt(place['id']), place['name']);
  Map toJson() => {'id': id, 'name': name};
}

int _toInt(id) => id is int ? id : int.parse(id);

来自 Chrome 开发工具的 Stacktrace

`dart_sdk.js:101652 EXCEPTION: Exception: Server error; cause: Type 'String' is not a subtype of expected type 'int'. STACKTRACE: packages/$sdk/dev_compiler/amd/dart_sdk.js 4835:29 throw packages/places/src/place/place_search_service.ddc.js 28:21 search packages/$sdk/dev_compiler/amd/dart_sdk.js 23385:33 onValue packages/stack_trace/stack_trace.ddc.js 142:98 .dart.fn packages/stack_trace/stack_trace.ddc.js 188:16 [_run] packages/stack_trace/stack_trace.ddc.js 142:80 arg packages/angular/src/core/zone/ng_zone.ddc.js 117:18 arg packages/$sdk/dev_compiler/amd/dart_sdk.js 29365:56 _rootRunUnary packages/$sdk/dev_compiler/amd/dart_sdk.js 28991:14 runUnary packages/angular/src/core/zone/ng_zone.ddc.js 114:21 [_runUnary] packages/$sdk/dev_compiler/amd/dart_sdk.js 29193:14 runUnary packages/$sdk/dev_compiler/amd/dart_sdk.js 25288:29 handleValue packages/$sdk/dev_compiler/amd/dart_sdk.js 25750:49 handleValueCallback packages/$sdk/dev_compiler/amd/dart_sdk.js 25780:17 _propagateToListeners packages/$sdk/dev_compiler/amd/dart_sdk.js 25643:23 [_completeWithValue] packages/$sdk/dev_compiler/amd/dart_sdk.js 25661:35 .scheduleMicrotask.dart.fn packages/angular/src/core/zone/ng_zone.ddc.js 92:11 safeMicrotask packages/stack_trace/stack_trace.ddc.js 188:16 [_run] packages/stack_trace/stack_trace.ddc.js 137:71 parent.registerCallback.dart.fn packages/angular/src/core/zone/ng_zone.ddc.js 107:18 parent.run.dart.fn packages/$sdk/dev_compiler/amd/dart_sdk.js 29359:14 _rootRun packages/$sdk/dev_compiler/amd/dart_sdk.js 28985:14 run packages/angular/src/core/zone/ng_zone.ddc.js 104:21 [_run] packages/$sdk/dev_compiler/amd/dart_sdk.js 29186:14 run packages/$sdk/dev_compiler/amd/dart_sdk.js 29106:14 runGuarded packages/$sdk/dev_compiler/amd/dart_sdk.js 29142:33 async._AsyncCallbackEntry.new.dart.fn packages/$sdk/dev_compiler/amd/dart_sdk.js 25990:13 _microtaskLoop packages/$sdk/dev_compiler/amd/dart_sdk.js 25996:13 _startMicrotaskLoop packages/$sdk/dev_compiler/amd/dart_sdk.js 26066:11 internalCallback

packages/$sdk/dev_compiler/amd/dart_sdk.js 29214:14 registerUnaryCallback packages/$sdk/dev_compiler/amd/dart_sdk.js 23396:22 async packages/places/src/place/place_search_service.ddc.js 23:20 search packages/places/src/place/place_list_component.ddc.js 69:58 search packages/$sdk/dev_compiler/amd/dart_sdk.js 23404:34 runBody packages/$sdk/dev_compiler/amd/dart_sdk.js 23431:7 async packages/places/src/place/place_list_component.ddc.js 65:20 search packages/places/src/place/place_list_component.template.ddc.js 158:16 [_handle_click_15_0] packages/angular/src/bootstrap/modules.ddc.js 1869:106 src__core__linker__app_view_utils.appViewUtils.eventManager.getZone.runGuarded.dart.fn packages/angular/src/core/zone/ng_zone.ddc.js 107:18 parent.run.dart.fn packages/$sdk/dev_compiler/amd/dart_sdk.js 29359:14 _rootRun packages/$sdk/dev_compiler/amd/dart_sdk.js 28985:14 run packages/angular/src/core/zone/ng_zone.ddc.js 104:21 [_run] packages/$sdk/dev_compiler/amd/dart_sdk.js 29186:14 run packages/$sdk/dev_compiler/amd/dart_sdk.js 29106:14 runGuarded packages/angular/src/core/zone/ng_zone.ddc.js 223:31 runGuarded packages/angular/src/bootstrap/modules.ddc.js 1869:81 event`

通过设置断点检查错误对象时

Symbol(_error) : Error at Object.dart.throw (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4835:29) at Object.dart.castError (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4462:15) at Object.dart.as (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4751:17) at Function.check_int [as _check] (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:9997:17) at Object.dart._checkApply (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4572:19) at Object.dart._checkAndCall (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4653:14) at Object.dart.callMethod (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4702:17) at Object.dart.dindex (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4717:17) at src__place__place_search_service.PlaceSearchService.new.[_extractData] (http://localhost:8080/packages/places/src/place/place_search_service.ddc.js:33:19) at src__place__place_search_service.PlaceSearchService.new.search (http://localhost:8080/packages/places/src/place/place_search_service.ddc.js:26:49) at search.next (<anonymous>) at onValue (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:23385:33) at (anonymous function).dart.fn (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:142:98) at src__stack_zone_specification.StackZoneSpecification.new.[_run] (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:188:16) at parent.registerUnaryCallback.dart.fn.arg (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:142:80) at parent.runUnary.dart.fn.arg (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:117:18) at async._rootRunUnary (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29365:56) at async._ZoneDelegate.new.runUnary (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:28991:14) at src__core__zone__ng_zone.NgZone.new.[_runUnary] (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:114:21) at async._CustomZone.new.runUnary (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29193:14) at _FutureListener.then.handleValue (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25288:29) at handleValueCallback (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25750:49) at Function._propagateToListeners (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25780:17) at _Future.new.[_completeWithValue] (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25643:23) at (anonymous function).scheduleMicrotask.dart.fn (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25661:35) at safeMicrotask (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:92:11) at src__stack_zone_specification.StackZoneSpecification.new.[_run] (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:188:16) at parent.registerCallback.dart.fn (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:137:71) at parent.run.dart.fn (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:107:18) at async._rootRun (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29359:14) at async._ZoneDelegate.new.run (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:28985:14) at src__core__zone__ng_zone.NgZone.new.[_run] (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:104:21) at async._CustomZone.new.run (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29186:14) at async._CustomZone.new.runGuarded (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29106:14) at async._AsyncCallbackEntry.new.dart.fn [as callback] (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29142:33) at Object.async._microtaskLoop (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25990:13) at async._startMicrotaskLoop (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25996:13) at MutationObserver.internalCallback (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:26066:11) stack : "Error↵ at Object.dart.throw (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4835:29)↵ at Object.dart.castError (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4462:15)↵ at Object.dart.as (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4751:17)↵ at Function.check_int [as _check] (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:9997:17)↵ at Object.dart._checkApply (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4572:19)↵ at Object.dart._checkAndCall (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4653:14)↵ at Object.dart.callMethod (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4702:17)↵ at Object.dart.dindex (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:4717:17)↵ at src__place__place_search_service.PlaceSearchService.new.[_extractData] (http://localhost:8080/packages/places/src/place/place_search_service.ddc.js:33:19)↵ at src__place__place_search_service.PlaceSearchService.new.search (http://localhost:8080/packages/places/src/place/place_search_service.ddc.js:26:49)↵ at search.next (<anonymous>)↵ at onValue (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:23385:33)↵ at (anonymous function).dart.fn (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:142:98)↵ at src__stack_zone_specification.StackZoneSpecification.new.[_run] (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:188:16)↵ at parent.registerUnaryCallback.dart.fn.arg (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:142:80)↵ at parent.runUnary.dart.fn.arg (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:117:18)↵ at async._rootRunUnary (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29365:56)↵ at async._ZoneDelegate.new.runUnary (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:28991:14)↵ at src__core__zone__ng_zone.NgZone.new.[_runUnary] (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:114:21)↵ at async._CustomZone.new.runUnary (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29193:14)↵ at _FutureListener.then.handleValue (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25288:29)↵ at handleValueCallback (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25750:49)↵ at Function._propagateToListeners (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25780:17)↵ at _Future.new.[_completeWithValue] (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25643:23)↵ at (anonymous function).scheduleMicrotask.dart.fn (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25661:35)↵ at safeMicrotask (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:92:11)↵ at src__stack_zone_specification.StackZoneSpecification.new.[_run] (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:188:16)↵ at parent.registerCallback.dart.fn (http://localhost:8080/packages/stack_trace/stack_trace.ddc.js:137:71)↵ at parent.run.dart.fn (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:107:18)↵ at async._rootRun (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29359:14)↵ at async._ZoneDelegate.new.run (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:28985:14)↵ at src__core__zone__ng_zone.NgZone.new.[_run] (http://localhost:8080/packages/angular/src/core/zone/ng_zone.ddc.js:104:21)↵ at async._CustomZone.new.run (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29186:14)↵ at async._CustomZone.new.runGuarded (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29106:14)↵ at async._AsyncCallbackEntry.new.dart.fn [as callback] (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:29142:33)↵ at Object.async._microtaskLoop (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25990:13)↵ at async._startMicrotaskLoop (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:25996:13)↵ at MutationObserver.internalCallback (http://localhost:8080/packages/$sdk/dev_compiler/amd/dart_sdk.js:26066:11)"

注释掉抛出_handleError

`dart_sdk.js:101652 EXCEPTION: TypeError: Cannot read property 'Symbol(dartx.length)' of undefined
STACKTRACE: 
packages/places/src/place/place_list_component.ddc.js 71:24  search
packages/$sdk/dev_compiler/amd/dart_sdk.js 23385:33          onValue
packages/stack_trace/stack_trace.ddc.js 142:98               .dart.fn
packages/stack_trace/stack_trace.ddc.js 188:16               [_run]
packages/stack_trace/stack_trace.ddc.js 142:80               arg
packages/angular/src/core/zone/ng_zone.ddc.js 117:18         arg
packages/$sdk/dev_compiler/amd/dart_sdk.js 29365:56          _rootRunUnary
packages/$sdk/dev_compiler/amd/dart_sdk.js 28991:14          runUnary
packages/angular/src/core/zone/ng_zone.ddc.js 114:21         [_runUnary]
packages/$sdk/dev_compiler/amd/dart_sdk.js 29193:14          runUnary
packages/$sdk/dev_compiler/amd/dart_sdk.js 25288:29          handleValue
packages/$sdk/dev_compiler/amd/dart_sdk.js 25750:49          handleValueCallback
packages/$sdk/dev_compiler/amd/dart_sdk.js 25780:17          _propagateToListeners
packages/$sdk/dev_compiler/amd/dart_sdk.js 25643:23          [_completeWithValue]
packages/$sdk/dev_compiler/amd/dart_sdk.js 25661:35          .scheduleMicrotask.dart.fn
packages/angular/src/core/zone/ng_zone.ddc.js 92:11          safeMicrotask
packages/stack_trace/stack_trace.ddc.js 188:16               [_run]
packages/stack_trace/stack_trace.ddc.js 137:71               parent.registerCallback.dart.fn
packages/angular/src/core/zone/ng_zone.ddc.js 107:18         parent.run.dart.fn
packages/$sdk/dev_compiler/amd/dart_sdk.js 29359:14          _rootRun
packages/$sdk/dev_compiler/amd/dart_sdk.js 28985:14          run
packages/angular/src/core/zone/ng_zone.ddc.js 104:21         [_run]
packages/$sdk/dev_compiler/amd/dart_sdk.js 29186:14          run
packages/$sdk/dev_compiler/amd/dart_sdk.js 29106:14          runGuarded
packages/$sdk/dev_compiler/amd/dart_sdk.js 29142:33          async._AsyncCallbackEntry.new.dart.fn
packages/$sdk/dev_compiler/amd/dart_sdk.js 25990:13          _microtaskLoop
packages/$sdk/dev_compiler/amd/dart_sdk.js 25996:13          _startMicrotaskLoop
packages/$sdk/dev_compiler/amd/dart_sdk.js 26066:11          internalCallback

packages/$sdk/dev_compiler/amd/dart_sdk.js 29214:14                    registerUnaryCallback
packages/$sdk/dev_compiler/amd/dart_sdk.js 23396:22                    async
packages/places/src/place/place_list_component.ddc.js 65:20            search
packages/places/src/place/place_list_component.template.ddc.js 158:16  [_handle_click_15_0]
packages/angular/src/bootstrap/modules.ddc.js 1869:106                 src__core__linker__app_view_utils.appViewUtils.eventManager.getZone.runGuarded.dart.fn
packages/angular/src/core/zone/ng_zone.ddc.js 107:18                   parent.run.dart.fn
packages/$sdk/dev_compiler/amd/dart_sdk.js 29359:14                    _rootRun
packages/$sdk/dev_compiler/amd/dart_sdk.js 28985:14                    run
packages/angular/src/core/zone/ng_zone.ddc.js 104:21                   [_run]
packages/$sdk/dev_compiler/amd/dart_sdk.js 29186:14                    run
packages/$sdk/dev_compiler/amd/dart_sdk.js 29106:14                    runGuarded
packages/angular/src/core/zone/ng_zone.ddc.js 223:31                   runGuarded
packages/angular/src/bootstrap/modules.ddc.js 1869:81                  event

error   @   dart_sdk.js:101652
handle  @   exceptions.dart:14
call    @   exceptions.dart:11
handleUncaughtException @   application_ref.dart:134
(anonymous function).(anonymous function).(anonymous function).onError.listen.dart.fn.error @   application_ref.dart:51
(anonymous function).dart.fn    @   stack_zone_specification.dart:129
[_run]  @   stack_zone_specification.dart:209
parent.registerUnaryCallback.dart.fn.arg    @   stack_zone_specification.dart:129
parent.runUnary.dart.fn.arg @   ng_zone.dart:190
async._rootRunUnary @   dart_sdk.js:29368
runUnary    @   dart_sdk.js:28991
[_runUnary] @   ng_zone.dart:187
runUnary    @   dart_sdk.js:29193
runUnaryGuarded @   dart_sdk.js:29114
[_sendData] @   dart_sdk.js:23973
[_add]  @   dart_sdk.js:23920
[_sendData] @   dart_sdk.js:24605
add @   dart_sdk.js:24415
[_onErrorWithLongStackTrace]    @   ng_zone.dart:228
async._rootRunBinary    @   dart_sdk.js:29377
runBinary   @   dart_sdk.js:29579
[_handleUncaughtError]  @   stack_zone_specification.dart:163
handleUncaughtError @   dart_sdk.js:29170
_propagateToListeners   @   dart_sdk.js:25693
[_completeWithValue]    @   dart_sdk.js:25643
(anonymous function).scheduleMicrotask.dart.fn  @   dart_sdk.js:25661
safeMicrotask   @   ng_zone.dart:163
[_run]  @   stack_zone_specification.dart:209
parent.registerCallback.dart.fn @   stack_zone_specification.dart:119
parent.run.dart.fn  @   ng_zone.dart:178
async._rootRun  @   dart_sdk.js:29359
run @   dart_sdk.js:28985
[_run]  @   ng_zone.dart:175
run @   dart_sdk.js:29186
runGuarded  @   dart_sdk.js:29106
dart.fn @   dart_sdk.js:29142
async._microtaskLoop    @   dart_sdk.js:25990
async._startMicrotaskLoop   @   dart_sdk.js:25996
internalCallback    @   dart_sdk.js:26066
childList (async)
dart.fn.callback    @   dart_sdk.js:26076
_scheduleImmediate  @   dart_sdk.js:26052
async._scheduleAsyncCallback    @   dart_sdk.js:26010
async._rootScheduleMicrotask    @   dart_sdk.js:29404
scheduleMicrotask   @   dart_sdk.js:29028
[_scheduleMicrotask]    @   ng_zone.dart:171
scheduleMicrotask   @   dart_sdk.js:29237
[_asyncComplete]    @   dart_sdk.js:25660
complete    @   dart_sdk.js:25194
reader.(anonymous function).first.then.dart.fn._    @   browser_client.dart:60
(anonymous function).dart.fn    @   stack_zone_specification.dart:129
[_run]  @   stack_zone_specification.dart:209
parent.registerUnaryCallback.dart.fn.arg    @   stack_zone_specification.dart:129
parent.runUnary.dart.fn.arg @   ng_zone.dart:190
async._rootRunUnary @   dart_sdk.js:29365
runUnary    @   dart_sdk.js:28991
[_runUnary] @   ng_zone.dart:187
runUnary    @   dart_sdk.js:29193
handleValue @   dart_sdk.js:25288
handleValueCallback @   dart_sdk.js:25750
_propagateToListeners   @   dart_sdk.js:25780
[_complete] @   dart_sdk.js:25634
async._cancelAndValue   @   dart_sdk.js:27687
subscription.listen.dart.fn.value   @   dart_sdk.js:10492
dart._checkAndCall  @   dart_sdk.js:4656
dart.dcall  @   dart_sdk.js:4661
(anonymous function).html$._wrapZone.dart.fn.e  @   dart_sdk.js:99172
(anonymous function).dart.fn    @   stack_zone_specification.dart:129
[_run]  @   stack_zone_specification.dart:209
parent.registerUnaryCallback.dart.fn.arg    @   stack_zone_specification.dart:129
parent.runUnary.dart.fn.arg @   ng_zone.dart:190
async._rootRunUnary @   dart_sdk.js:29368
runUnary    @   dart_sdk.js:28991
[_runUnary] @   ng_zone.dart:187
runUnary    @   dart_sdk.js:29193
runUnaryGuarded @   dart_sdk.js:29114
dart.fn.arg @   dart_sdk.js:29146
load (async)
[_addEventListener] @   dart_sdk.js:57186
[dartx.addEventListener]    @   dart_sdk.js:57176
[_tryResume]    @   dart_sdk.js:99153
_EventStreamSubscription.new    @   dart_sdk.js:99173
listen  @   dart_sdk.js:98974
get first   @   dart_sdk.js:10491
async.async.xhr.(anonymous function).first.then.dart.fn._   @   browser_client.dart:58
(anonymous function).dart.fn    @   stack_zone_specification.dart:129
[_run]  @   stack_zone_specification.dart:209
parent.registerUnaryCallback.dart.fn.arg    @   stack_zone_specification.dart:129
parent.runUnary.dart.fn.arg @   ng_zone.dart:190
async._rootRunUnary @   dart_sdk.js:29365
runUnary    @   dart_sdk.js:28991
[_runUnary] @   ng_zone.dart:187
runUnary    @   dart_sdk.js:29193
handleValue @   dart_sdk.js:25288
handleValueCallback @   dart_sdk.js:25750
_propagateToListeners   @   dart_sdk.js:25780
[_complete] @   dart_sdk.js:25634
async._cancelAndValue   @   dart_sdk.js:27687
subscription.listen.dart.fn.value   @   dart_sdk.js:10492
dart._checkAndCall  @   dart_sdk.js:4656
dart.dcall  @   dart_sdk.js:4661
(anonymous function).html$._wrapZone.dart.fn.e  @   dart_sdk.js:99172
(anonymous function).dart.fn    @   stack_zone_specification.dart:129
[_run]  @   stack_zone_specification.dart:209
parent.registerUnaryCallback.dart.fn.arg    @   stack_zone_specification.dart:129
parent.runUnary.dart.fn.arg @   ng_zone.dart:190
async._rootRunUnary @   dart_sdk.js:29368
runUnary    @   dart_sdk.js:28991
[_runUnary] @   ng_zone.dart:187
runUnary    @   dart_sdk.js:29193
runUnaryGuarded @   dart_sdk.js:29114
dart.fn.arg @   dart_sdk.js:29146
load (async)
[_addEventListener] @   dart_sdk.js:57186
[dartx.addEventListener]    @   dart_sdk.js:57176
[_tryResume]    @   dart_sdk.js:99153
_EventStreamSubscription.new    @   dart_sdk.js:99173
listen  @   dart_sdk.js:98974
get first   @   dart_sdk.js:10491
send    @   browser_client.dart:52
onValue @   dart_sdk.js:23385
(anonymous function).dart.fn    @   stack_zone_specification.dart:129
[_run]  @   stack_zone_specification.dart:209
parent.registerUnaryCallback.dart.fn.arg    @   stack_zone_specification.dart:129
parent.runUnary.dart.fn.arg @   ng_zone.dart:190
async._rootRunUnary @   dart_sdk.js:29365
runUnary    @   dart_sdk.js:28991
[_runUnary] @   ng_zone.dart:187
runUnary    @   dart_sdk.js:29193
handleValue @   dart_sdk.js:25288
handleValueCallback @   dart_sdk.js:25750
_propagateToListeners   @   dart_sdk.js:25780
[_completeWithValue]    @   dart_sdk.js:25643
(anonymous function).scheduleMicrotask.dart.fn  @   dart_sdk.js:25661
safeMicrotask   @   ng_zone.dart:163
[_run]  @   stack_zone_specification.dart:209
parent.registerCallback.dart.fn @   stack_zone_specification.dart:119
parent.run.dart.fn  @   ng_zone.dart:178
async._rootRun  @   dart_sdk.js:29359
run @   dart_sdk.js:28985
[_run]  @   ng_zone.dart:175
run @   dart_sdk.js:29186
runGuarded  @   dart_sdk.js:29106
dart.fn @   dart_sdk.js:29142
async._microtaskLoop    @   dart_sdk.js:25990
async._startMicrotaskLoop   @   dart_sdk.js:25996
internalCallback    @   dart_sdk.js:26066
childList (async)
dart.fn.callback    @   dart_sdk.js:26076
_scheduleImmediate  @   dart_sdk.js:26052
async._scheduleAsyncCallback    @   dart_sdk.js:26010
async._rootScheduleMicrotask    @   dart_sdk.js:29404
scheduleMicrotask   @   dart_sdk.js:29028
[_scheduleMicrotask]    @   ng_zone.dart:171
scheduleMicrotask   @   dart_sdk.js:29237
async.scheduleMicrotask @   dart_sdk.js:26048
schedule    @   dart_sdk.js:26968
[_setPendingEvents] @   dart_sdk.js:23798
[_createSubscription]   @   dart_sdk.js:26927
listen  @   dart_sdk.js:23656
listen  @   dart_sdk.js:26156
toBytes @   byte_stream.dart:24
send    @   browser_client.dart:43
runBody @   dart_sdk.js:23404
async.async @   dart_sdk.js:23431
send    @   browser_client.dart:42
_sendUnstreamed @   base_client.dart:171
runBody @   dart_sdk.js:23404
async.async @   dart_sdk.js:23431
[_sendUnstreamed]   @   base_client.dart:152
get @   base_client.dart:34
search  @   place_search_service.dart:16
runBody @   dart_sdk.js:23404
async.async @   dart_sdk.js:23431
search  @   place_search_service.dart:14
search  @   place_list_component.dart:54
runBody @   dart_sdk.js:23404
async.async @   dart_sdk.js:23431
search  @   place_list_component.dart:50
[_handle_click_15_0]    @   place_list_component.template.dart:160
src__core__linker__app_view_utils.appViewUtils.eventManager.getZone.runGuarded.dart.fn  @   app_view.dart:619
parent.run.dart.fn  @   ng_zone.dart:178
async._rootRun  @   dart_sdk.js:29359
run @   dart_sdk.js:28985
[_run]  @   ng_zone.dart:175
run @   dart_sdk.js:29186
runGuarded  @   dart_sdk.js:29106
runGuarded  @   ng_zone.dart:333
dart.fn.event`

发现错误。实际上在Mock界面中是:

dynamic _extractData(Response resp) => json.decode(resp.body)[data];

但在 Aqueduct 界面中,响应未包含在 JSON "data" 标记中。所以将其更改为

dynamic _extractData(Response resp) => json.decode(resp.body); 

解决了我的问题。

所以当出现如下错误时:

TypeError: Cannot read property 'Symbol(dartx.length)' of undefined

这很可能意味着响应可能不包含正确的 json。