Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

725
Vistas
value for uri cannot be cast from double to string

I want to set a default image before i can upload any image from my gallery here is my code

 state = {
        user: {
            avatar : require('../assets/user.png')

        }
    }
    handlePickAvatar = async () => {

        UserPermission.getCamerPermission()
        let result = await ImagePicker.launchImageLibraryAsync({
            mediaTypes : ImagePicker.MediaTypeOptions.Images,
            allowsEditing: true,
            aspect:[4,3]
        })
        if (!result.cancelled) {
            this.setState({ user: { ...this.state.user, avatar: result.uri } });
        }
    }
    render() {

        return (
            <View style={styles.container}>
                <Text style={styles.profile}>Profile</Text>
                <View style={styles.avatarPlaceholder} >
                    <Image source={{ uri: this.state.user.avatar }}  style={styles.avatar} />


                </View>
                <TouchableOpacity onPress={this.handlePickAvatar}>
                    <Text style={styles.text}>Load Image</Text>                    
                </TouchableOpacity>
            </View>
        );
    }

The results should be like this the user image must be defaulted but i get the error :value for uri cannot be cast from double to string

is there any solution for this ?

Thank you! Updated!!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Check if user.avatar has the image then show the uploaded image. If it is not uploaded show the default image.

  <View style={styles.container}>
    <View style={styles.avatarPlaceholder}>
      <Image
        source={{ uri: this.state.user.avatar || 'default image path' }}
        style={styles.avatar}
      />
    </View>
    <TouchableOpacity onPress={this.handlePickAvatar}>
      <Text style={styles.text}>Load Image</Text>
    </TouchableOpacity>
  </View>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda