dart 命名参数“queryParameters”是必需的,但没有相应的参数,尝试添加所需的参数

enxuqcxy  于 2023-06-19  发布在  其他
关注(0)|答案(1)|浏览(157)

请帮帮我这里有很多这些都是我一直面临的同样的问题。
主要问题是-命名参数'是必需的,但没有相应的参数。
问题部分- ```

Future<ApiResponse> forgetPassword(String identity) async {
    try {
      log(identity);
      Response response = await dioClient.post(AppConstants.FORGET_PASSWORD_URI, 
     data: {"identity": identity}
**Problem message** -
*The named parameter 'queryParameters' is required, but there's no corresponding argument.
Try adding the required argument*
import 'dart:developer';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:eamar_seller_app/data/datasource/remote/dio/dio_client.dart';
import 'package:eamar_seller_app/data/datasource/remote/exception/api_error_handler.dart';
import 'package:eamar_seller_app/data/model/response/base/api_response.dart';
import 'package:eamar_seller_app/utill/app_constants.dart';

class AuthRepo {
 late final DioClient dioClient;
 late final SharedPreferences sharedPreferences;
  AuthRepo({required this.dioClient, required this.sharedPreferences});

  Future<ApiResponse> login({String? emailAddress, String? password}) async {
    try {
      Response response = await dioClient.post(
        AppConstants.LOGIN_URI, data:
         {"email": emailAddress, "password": password},
      );
      return ApiResponse.withSuccess(response);
    } catch (e) {
     return ApiResponse.withError(ApiErrorHandler.getMessage(e));
    }
  }

  Future<ApiResponse> forgetPassword(String identity) async {
    try {
      log(identity);
      Response response = await dioClient.post(AppConstants.FORGET_PASSWORD_URI, 
     data: {"identity": identity}
      
      );
      log(response.toString());
      return ApiResponse.withSuccess(response);
    } catch (e) {
      log(e.toString());
      return ApiResponse.withError(ApiErrorHandler.getMessage(e));
    }
  }

  Future<ApiResponse> resetPassword(String identity, String otp ,String password, String confirmPassword) async {
    try {
      Response response = await dioClient.post(
          AppConstants.RESET_PASSWORD_URI, data: {"_method" : "put",
        "identity": identity.trim(), "otp": otp,
        "password": password, "confirm_password":confirmPassword});
      return ApiResponse.withSuccess(response);
    } catch (e) {
      return ApiResponse.withError(ApiErrorHandler.getMessage(e));
    }
  }

  Future<ApiResponse> verifyOtp(String identity, String otp) async {
    try {
      Response response = await dioClient.post(
          AppConstants.VERIFY_OTP_URI, data: {"identity": identity.trim(), "otp": otp});
      return ApiResponse.withSuccess(response);
    } catch (e) {
      return ApiResponse.withError(ApiErrorHandler.getMessage(e));
    }
  }

  Future<ApiResponse> updateToken() async {
    try {
      String _deviceToken = await _getDeviceToken();
      FirebaseMessaging.instance.subscribeToTopic(AppConstants.TOPIC);
      Response response = await dioClient.post(
        AppConstants.TOKEN_URI,
        data: {"_method": "put", "cm_firebase_token": _deviceToken},
      );
      return ApiResponse.withSuccess(response);
    } catch (e) {
      return ApiResponse.withError(ApiErrorHandler.getMessage(e));
    }
  }

  Future<String> _getDeviceToken() async {
    String _deviceToken;
    if(Platform.isIOS) {
      _deviceToken = (await FirebaseMessaging.instance.getAPNSToken())!;
    }else {
      _deviceToken = (await FirebaseMessaging.instance.getToken())!;
    }

    print('--------Device Token---------- '+_deviceToken);
    return _deviceToken;
  }

  // for  user token
  Future<void> saveUserToken(String token) async {
    dioClient.token = token;
    dioClient.dio.options.headers = {'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Bearer $token'};

    try {
      await sharedPreferences.setString(AppConstants.TOKEN, token);
    } catch (e) {
      throw e;
    }
  }

  String getUserToken() {
    return sharedPreferences.getString(AppConstants.TOKEN) ?? "";
  }

  bool isLoggedIn() {
    return sharedPreferences.containsKey(AppConstants.TOKEN);
  }

  Future<bool> clearSharedData() async {
    await FirebaseMessaging.instance.unsubscribeFromTopic(AppConstants.TOPIC);
    return sharedPreferences.remove(AppConstants.TOKEN);
    //return sharedPreferences.clear();
  }

  // for  Remember Email
  Future<void> saveUserNumberAndPassword(String number, String password) async {
    try {
      await sharedPreferences.setString(AppConstants.USER_PASSWORD, password);
      await sharedPreferences.setString(AppConstants.USER_EMAIL, number);
    } catch (e) {
      throw e;
    }
  }

  String getUserEmail() {
    return sharedPreferences.getString(AppConstants.USER_EMAIL) ?? "";
  }

  String getUserPassword() {
    return sharedPreferences.getString(AppConstants.USER_PASSWORD) ?? "";
  }

  Future<bool> clearUserNumberAndPassword() async {
    await sharedPreferences.remove(AppConstants.USER_PASSWORD);
    return await sharedPreferences.remove(AppConstants.USER_EMAIL);
  }

}
sqxo8psd

sqxo8psd1#

错误指出namedParameter 'queryParameters'是必需的。
你应该在你的方法中添加所需的参数:

Response response = await dioClient.post(
  AppConstants.FORGET_PASSWORD_URI,
  data: {"identity": identity},
  queryParameters: {}, 
);

相关问题