如何硬编码 API 集成 true/false

how to hardcode API integration true/false

我想将 is_verified 字段硬编码为 true 到我的飞镖代码中。因为我打算稍后实施该部分。我怎样才能做到这一点。下面是我为 API 集成实现的代码。 (不包括 (is_verified) 字段。)如何对该字段进行硬编码。同样,当我单击“注册”按钮时,API 调用部分无法正常工作。也想知道这方面的建议。 full signup.dart code

[![enter image description here] 3]3

Future UserSignUp(File file) async {
  String fileName = file.path.split('/').last;

  dioo.FormData data = dioo.FormData.fromMap({
    "image": await dioo.MultipartFile.fromFile(file.path,
        filename: fileName, contentType: MediaType.parse('image/jpg')),
    'userName': userName,
    'email': email,
    'mobileNumber': mobileNumber,
    'password': password,
    'dob':dob,

  });

  print(email);
  print(userName);
  print(image);
  print(data);
  try {
    var response = await Dio().post(BASE_API + "user/register",
        data: data,
        options: Options(headers: {'Content-Type': 'application/json'}));

    print(response);
    if (response.data["message"] == "Successfully signed up .") {
      Get.snackbar(
        "Message",
        "Please check your email to verify your account",
        backgroundColor: buttontext.withOpacity(0.5),
        colorText: textWhite,
      );
      Get.to(const LoginScreen());
    } else if (response.data["code"] == 200) {
      Get.snackbar("Message", "Email Adresss is already exist.",
          backgroundColor: buttontext.withOpacity(0.5),
          borderWidth: 1,
          borderColor: Colors.grey,
          colorText: textWhite,
          icon: const Icon(
            Icons.error_outline_outlined,
            color: Colors.red,
            size: 30,
          ));
    } else {
      Get.snackbar("error", "No User Found");
    }
  } on DioError catch (e) {
    Get.snackbar("Error", "Something went wrong.Please contact admin",
        backgroundColor: buttontext.withOpacity(0.5),
        borderWidth: 1,
        borderColor: Colors.grey,
        colorText: textWhite,
        icon: const Icon(
          Icons.error_outline_outlined,
          color: Colors.red,
          size: 30,
        ));
    print(e.error.toString());
  }
}

//调用API

Container(
                  padding: EdgeInsets.all(30.0),
                  child: GestureDetector(
                      child: MainButton("Sign Up"),
                      onTap: () async {
                        await UserSignUp(image!).then((value) {});

                        setState(() {
                          isLoading = false;
                          pointerIgnore = false;
                        });

您可以轻松地将其添加到您的 post 请求中

 dioo.FormData data = dioo.FormData.fromMap({
    "image": await dioo.MultipartFile.fromFile(file.path,
        filename: fileName, contentType: MediaType.parse('image/jpg')),
    'userName': userName,
    'email': email,
    'mobileNumber': mobileNumber,
    'password': password,
    'dob':dob,
"is_verified":true,...

关于你的第二个

also when I CLICK Signup button the API calling part is not working

很难说,你可以尝试使用 FormData.fromMap( 而不是 dioo.FormData.fromMap( 因为我们不知道 dioo 是什么意思,

打印语句打印任何数据吗?