Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter circle file image with clip oval

Tags:

flutter

dart

I want to clip an image that I extracted from the image picker plugin and it does not work with BoxDecoration.circle , so I want to clip it as circle with oval clipper. How to achive it ?

like image 235
Osama Gamal Avatar asked May 30 '18 11:05

Osama Gamal


People also ask

How do you show an image in a circle shape in Flutter?

To display a Round Image in Flutter, you can use Container with BoxDecoration, and use BoxShape. circle for shape and provide the image for image property.

How do you use ClipOval in Flutter?

ClipOval widget clips the child widget in oval or circle shape. We can reshape the child widget by changing width and height. If width and height are equal the shape will be circular.


2 Answers

You can use CircleAvatar widget to display the obtained image to make it circular.

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(new MaterialApp(debugShowCheckedModeBanner: false, home: new MyApp()));

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  File _image;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);

    setState(() {
      _image = image;
    });
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Home'),
      ),
      body: new Center(
        child: _image == null
            ? new Text('No image selected.')
            : new CircleAvatar(backgroundImage: new FileImage(_image), radius: 200.0,),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: getImage,
        tooltip: 'Pick Image',
        child: new Icon(Icons.add_a_photo),
      ),
    );
  }
}
like image 108
Vinoth Kumar Avatar answered Oct 15 '22 21:10

Vinoth Kumar


You can also use ClipOval to circle the image. Just wrap your file image with ClipOval.

ClipOval(
  child: FileImage(_image)
),
like image 36
Vinoth Vino Avatar answered Oct 15 '22 19:10

Vinoth Vino