How to resize the width of the image in flutter?

499

You can use CircleAvatar instead of ClipOval like below and it will be a better choice.

CircleAvatar class you can check

Container(
  width: 50,
  child: CircleAvatar(
    backgroundColor: Colors.transparent,
    radius: 90.0,
    child: Image.asset(
      "assets/face.jpg",
      height: 50.0,
      width: 50.0,
      fit: BoxFit.fill
    ),
  )
)
Share:
499
황희윤
Author by

황희윤

Updated on January 05, 2023

Comments

  • 황희윤
    황희윤 over 1 year

    enter image description here

    Hello! The width of the image is same as the width of the phone screen. What's the problem and how can I reduce the size of the width? Thank you!

    class _SignupProfileImageState extends State<SignupProfileImage> {
      bool isUploadImage = false;
      var selectedImage;
    
      @override
      Widget build(BuildContext context) {
        return Positioned(
            top: 140,
            right: 0,
            left: 0,
            child: SizedBox(
              height: 100,
              width: 100,
              child: Stack(
                clipBehavior: Clip.none,
                fit: StackFit.expand,
                children: [
                  Container(
          width: 50,
          child: ClipOval(
            child: Image.asset(
              'assets/face.jpg',
              height: 50.0,
              width: 50.0,
              fit: BoxFit.fill              
                ],
              ),
            )
        );
      }
    }
    
    • Paweł
      Paweł almost 2 years
      You set positioned right and left, so image is streetch to full width, remove it and check what happend :)
    • 황희윤
      황희윤 almost 2 years
      Thank you for your advice. However, if I remove it, then I can't put the image in center :( I wrapped the image with Center widget, but didn't work. How can I fix this problem?
    • rasityilmaz
      rasityilmaz almost 2 years
      try BoxFit.contain
    • 황희윤
      황희윤 almost 2 years
      I just tried it now and the image is in the squared box not circled box
    • Paweł
      Paweł almost 2 years
      put it to the row?