异常:类型“ HttpRequestEventTarget”不是预期类型“ HttpRequest”的子类型

时间:2018-07-18 18:21:32

标签: dart angular-dart

我需要HTTP请求,但出现异常,

异常:类型'HttpRequestEventTarget'不是预期类型'HttpRequest'的子类型。

我在使用该代码时遇到麻烦,请您帮我改正它。

import 'dart:async';
import 'dart:convert';

import 'package:angular/angular.dart';
import 'package:angular_router/angular_router.dart';
import 'package:flowapp/src/person.dart';
import 'package:flowapp/src/workflow_base.dart';
import 'package:http/http.dart';
import '../globals.dart' as globals;

@Injectable()
class SignInService {
  static const _baseURL = WorkFlowBase.baseUrl;
  stacit final _headers = {'Content-Type': 'application/json'};  

  final Client _http;
  final Router _router;

  SignInService(this._http, this._router);

  /// SignIn 
  /// -------

  Future<List<Person>> loginWorkflow(String username, String password) async {
    try {
      final response = await _http.post(
        _baseURL + '/signin', 
        headers: _headers,
        body: json.encode({
          'username': username,
          'password': password
        })
      );

      final person = (_extractData(response) as List)
        .map((value) => Person.fromJson(value))
        .toList();

      return person;
    } catch (e) {
      throw _handleError(e, 'loginWorkFlow()');
    }
  }

  dynamic _extractData(Response resp) => json.decode(resp.body);
  Exception _handleError(dynamic e, String methodName) {
    return Exception('Error : Method: $methodName ERROR: $e');
  }
}

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我为页面加载状态添加了PaceJs。我停止使用它。

PACE https://github.hubspot.com/pace/docs/welcome/