To crop the image, we will use two widgets,
first, we will use AspectRatio Widget.
Now, after we have defined the desired size, we can use the “decoration” property of the container and give it a BoxDecoration.
Now apply your image to “image”
Note – you can use fit as per your need,
Here i don’t want to compromise with the image width so i have used “fit : BoxFit.fitWidth”
image: DecorationImage( fit: BoxFit.fitWidth, alignment: FractionalOffset.topCenter, image: NetworkImage('https://pixabay.com/photos/crimson-rosella-parrot-bird-animal-7947000/'), )
So our complete code with aspect ratio would be,
AspectRatio( aspectRatio: 487 / 451, child: Container( decoration: const BoxDecoration( image: DecorationImage( fit: BoxFit.fitWidth, alignment: FractionalOffset.topCenter, image: NetworkImage('https://pixabay.com/photos/crimson-rosella-parrot-bird-animal-7947000/'), ) ), ), ),
Work with our skilled Flutter developers to accelerate your project and boost its performance.
Hire Flutter Developers