【问题标题】:Exception: Type 'HttpRequestEventTarget' is not a subtype of expected type 'HttpRequest'例外:类型“HttpRequestEventTarget”不是预期类型“HttpRequest”的子类型
【发布时间】:2018-07-18 18:21:32
【问题描述】:

我需要 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');
  }
}

【问题讨论】:

  • 我使用的是 Angular 5.0.0-beta+1,Dart 版本 2.0.0-dev.69.0 (beta)

标签: dart angular-dart


【解决方案1】:

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

佩斯https://github.hubspot.com/pace/docs/welcome/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 2020-06-24
    • 2022-08-12
    • 1970-01-01
    • 2020-06-26
    相关资源
    最近更新 更多