How to use profile image in flutter?

Asked

Viewed 1,139 times

0

I have a card represented by showing the user photo + its name, when I search for a local image it loads the image normally, but when I need to load this image through a link of my api it does not load.

Illustration image inserir a descrição da imagem aqui

Code:

return ListView(
          children: <Widget>[

            _qrCodeWidget(this.bytes, context),

            Container(
              child: Column(
                children: <Widget>[
                  SlimyCard(
              color: Color(0xffccffcc),
              topCardWidget: topCardWidget((snapshot.data)
                ? 'imagens/${gv.foto}'
                : ''), 

            ),
                ],
              ),

            ),
          ],
        );

The correct location you’d like to place is inside topCardWidget: topCardWidget((snapshot.data) ? 'imagens/${gv.foto}' : ''),

There is another way to put this image, but did not answer me for example. In this code above it calls the method topCardWidget within it we have the following code:

 Widget topCardWidget(String imagePath) {

return Column(
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    Container(
      child: Image.network('https://www.google.com/imgres?imgurl=https%3A%2F%2Fstorage.googleapis.com%2Fgweb-uniblog-publish-prod%2Fimages%2FAndroid_symbol_green_2.max-1500x1500.png&imgrefurl=https%3A%2F%2Fwww.blog.google%2Fproducts%2Fandroid%2F&docid=SDYhQ-MI_6500M&tbnid=rL2RK3y7U-kTxM%3A&vet=10ahUKEwiY0p7Ey5TmAhXkIbkGHYlbBtMQMwh3KAAwAA..i&w=1500&h=803&bih=635&biw=1024&q=android&ved=0ahUKEwiY0p7Ey5TmAhXkIbkGHYlbBtMQMwh3KAAwAA&iact=mrc&uact=8'),
      height: 70,
      width: 70,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(15),
        image: DecorationImage(image: AssetImage(imagePath)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: 20,
            spreadRadius: 1,
          ),
        ],
      ),
    ),
    SizedBox(height: 15),
    Text(
      '${gv.nome}',
      style: TextStyle(color: Color(0xff1e1e1e), fontSize: 20, fontWeight: FontWeight.bold),
    ),
    SizedBox(height: 15),
    Text(
      'Para escanear precione o ícone da câmera!',
      style: TextStyle(
          color: Color(0xff1e1e1e),
          fontSize: 15,
          fontWeight: FontWeight.w500),
    ),
    SizedBox(height: 10),
  ],
);
 }

on the line child: Image.network('https://www.google.com/imgres?imgurl=https%3A%2F%2Fstorage.googleapis.com%2Fgweb-uniblog-publish-prod%2Fimages%2FAndroid_symbol_green_2.max-1500x1500.png&imgrefurl=https%3A%2F%2Fwww.blog.google%2Fproducts%2Fandroid%2F&docid=SDYhQ-MI_6500M&tbnid=rL2RK3y7U-kTxM%3A&vet=10ahUKEwiY0p7Ey5TmAhXkIbkGHYlbBtMQMwh3KAAwAA..i&w=1500&h=803&bih=635&biw=1024&q=android&ved=0ahUKEwiY0p7Ey5TmAhXkIbkGHYlbBtMQMwh3KAAwAA&iact=mrc&uact=8'), I can place any link, but it loses image formatting with rounded edges and leaves only square.

  • Opa good afternoon, I will not post as an answer why I am not at home on my pc to show you an example, but I did it as follows, I took the image and passed it to a Boxdecoration inside the container but using the property of the Container itself. Try this and tell me if it worked, if you can’t, as soon as I get home today I’ll set an example here for you of how my code turned out.

  • Matheus, :)

  • Opa Thiago, yes I can as soon as I get home I assemble an example of how I did, now I am at work hehe but as soon as I arrive I already assemble and put as answer here for you dai, vlww

  • opa Thiago blz, I was looking at the topic and noticed a mistake, I don’t know if you’ve noticed, but precione is written wrong in your app :)

  • 1

    Opa I’ve changed it rs, already changed some things worth.

1 answer

1


Opa Thiago goodnight, as promised here is an example of how I used Boxdecoration to leave the images with rounded edges:

Here is an example of a rectangle with rounded edges:

Decoration boxDecorationRetangularImagem({double raioBorda, String linkImage}) {
  return new BoxDecoration(
    color: Colors.grey[300],
    shape: BoxShape.rectangle,
    borderRadius: BorderRadius.circular(raioBorda),
    image: new DecorationImage(image: CachedNetworkImageProvider(linkImage), fit: BoxFit.fill),
  );
}

And here an example of a circle with a facebook-style image:

Decoration boxDecorationCircularImagem({String linkImage}) {
  return new BoxDecoration(
    color: Colors.white,
    shape: BoxShape.circle,
    image: new DecorationImage(image: CachedNetworkImageProvider(linkImage), fit: BoxFit.fill),
  );
}
  • Matheus ball show, thank you very much for the answer!

  • Show I’m glad it worked, it worked?

  • Perfectly! Thanks so guy :)

  • Ball show :D happy that worked, a good night and good studies

  • Thanks for the force Matheus.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.