登录方法“_mulFromInteger”被调用为空

sign in The method '_mulFromInteger' was called on null

我已经在我的供应商中获得了登录方法。

  Future<void> signIn(
      String email, String password, BuildContext context) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    final clientID = "com.super.app";
    final body = "username=$email&password=$password&grant_type=password";
    final String clientCredentials =
        const Base64Encoder().convert("$clientID:".codeUnits);

    try {
      final http.Response response =
          await http.post("http://localhost:8888/auth",
              headers: {
                "Content-Type": "application/x-www-form-urlencoded",
                "Authorization": "Basic $clientCredentials"
              },
              body: body);
      final jsonResponse = json.decode(response.body);
//      if (jsonResponse["error"] != null) {
//        throw HttpException(jsonResponse["error"]);
//      }
      _userId = 1;
      _token = jsonResponse['access_token'];
      _expiryDate = DateTime.now().add(
        Duration(
          seconds: jsonResponse['expires_in'],
        ),
      );
      _autoLogout();
      notifyListeners();
      final userData = json.encode(
        {
          'userId': 1,
          'email': email,
          'token': _token,
          'expiryDate': _expiryDate.toIso8601String(),
        },
      );
      sharedPreferences.setString('userData', userData);
    } catch (error) {
      print(error.toString()); //<-- misleading error
    }
  }

一切正常,但当传递的登录凭据不正确时,我会收到误导性错误

flutter: NoSuchMethodError: The method '_mulFromInteger' was called on null.
Receiver: null
Tried calling: _mulFromInteger(1000000)

后端传递错误代码 400 和正文 {"error": "invalid client"} 但我得到那个奇怪的错误作为输出。那么这个错误是什么意思,为什么我得到那个而不是 body

根据@Suragch 的评论,我的代码几乎没有问题。首先我认为当服务器 return 400 代码然后它会自动抛出错误并跳过其余行..我错了所以基本上我不得不取消注释我的代码以获取 http 异常并在我的按钮中捕获错误

  try {
    await Provider.of<Auth>(context, listen: false).signIn(
        emailController.text, passwordController.text);
  } on HttpException catch (error) {
    print(error.toString());
  } catch (error) {
    print(error);
  }