Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

724
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!