Sandro Basharuli
Sandro Basharuli

Reputation: 35

how to round image that is not square, for example rectangle

enter image description here

I have code like this

ClipRRect(
                              borderRadius:
                                  BorderRadius.all(Radius.circular(100.0)),
                              child: Image.network(
                                image_link_from_api,
                                width: 100,
                                height: 100,
                                fit: BoxFit.fill,
                              ),
                            ),

I tried ClipRRect, avatar image, container with rounded corners, nothing seems to work, so how can I fill whole round image instead of something like this in above image?

I tried fill, cover, contain, every possible option

Upvotes: 0

Views: 490

Answers (1)

yushulx
yushulx

Reputation: 12150

The effect of running your code:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(100.0)),
              child: Image.network(
                'https://i.ibb.co/37ZfCpQ/20230113213218image-thumbnail-media-433.jpg',
                width: 100,
                height: 100,
                fit: BoxFit.fill,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

enter image description here

Upvotes: 1

Related Questions