Bool is not a subtype of type String in type cast

When i pass the bool value i had this error

The value expected is String and you are passing bool value. Please share a code snippet then maybe I can pinpoint the change to resolve this.

Future<void> verify(String phone_number, String otp_code) async {
    String encyptOTP = md5.convert(utf8.encode(otp_code)).toString();
    try {
      if (_phoneNumber == phone_number) {
        if (_otpCode == encyptOTP) {
          final url =
              'http://phplaravel-120732-1598764.cloudwaysapps.com/api/app-users';
          final response = await http.post(
            url,
            body: {
              'is_verified': true,
              // 'otp_code': '',
            },
          );
          final responseData = json.decode(response.body);
          print(responseData);
          print('otp match');
        }
      }
      notifyListeners();
    } catch (error) {
      throw error;
    }
  }

@ReeganAntony which line are you getting the error? Your code is looking fine to me.

‘is_verified’:true, This line i had an error

@ReeganAntony Put your body in another variable and json encode it.

Future<void> verify(String phone_number, String otp_code) async {
    String encyptOTP = md5.convert(utf8.encode(otp_code)).toString();
    try {
      if (_phoneNumber == phone_number) {
        if (_otpCode == encyptOTP) {
          final url =
              'http://phplaravel-120732-1598764.cloudwaysapps.com/api/app-users';
         final body =  {
              'is_verified': true,
              // 'otp_code': '',
            };
          final response = await http.post(
            url,
            body: json.encode(body) 
          );
          final responseData = json.decode(response.body);
          print(responseData);
          print('otp match');
        }
      }
      notifyListeners();
    } catch (error) {
      throw error;
    }
  }

Thank you so much…

1 Like