Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a small rounded rectangle in Flutter

Tags:

flutter

dart

The red rectangle center of my widget is too big and is not responsive to width and height arguments.

I have updated flutter, and android studio. I started with a container in the shape of a circle then, I used a flatbutton and gave it a shape. but when it becomes the rectangle it is the same size as the circle it resizes in. _isRecord is a boolean that is toggled when the button is pressed.

return Container(
  width: 80.0,
  height: 80.0,
  child: Container(
    child: FlatButton(
      onPressed: _press,
     ),
    decoration: new BoxDecoration(
      color: Colors.red,
      shape: _isRecording ? BoxShape.rectangle : BoxShape.circle,
      borderRadius: _isRecording ? BorderRadius.all(Radius.circular(8.0)) : null,
    ),
  ),
  decoration: new BoxDecoration(
    color: Colors.black,
    shape: BoxShape.circle,
    border: Border.all(width: 5.0, color: Colors.white),
  ),
);

It should look and function like the Voice Memos' record button. It should be a white circle stroke with a red center that when pressed becomes a smaller, rounded rectangle.

like image 202
TotallyGamerJet Avatar asked Jan 17 '19 21:01

TotallyGamerJet


People also ask

How do you round the edges of a container in Flutter?

bottomLeft: Radius. circular(40.0)), is used make a circular border at the bottom left of the container. this can be used to make a container circular at the corners you choose to make a circle.

How do you add a radius in Flutter?

Just Add decoration to your container. use BoxDecoration property in decoration. BoxDecoration has borderRadius Property. give specify border radius to your Container.


1 Answers

You can use your Widget inside Padding

exam:

    InkWell(
      splashColor: Colors.transparent,
      highlightColor: Colors.transparent,
      onTap: () {
        setState(() {
          _isRecording = !_isRecording;
        });
      },
      child: DecoratedBox(
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          border: Border.all(width: 5.0, color: Colors.white),
        ),
        child: Padding(
          padding: EdgeInsets.all(32.0),
          child: Container(
            width: 40.0,
            height: 40.0,
            child: Container(
              decoration: new BoxDecoration(
                color: Colors.red,
                shape:
                    _isRecording ? BoxShape.rectangle : BoxShape.circle,
                borderRadius: _isRecording
                    ? BorderRadius.all(Radius.circular(8.0))
                    : null,
              ),
            ),
          ),
        ),
      ),
    )
like image 184
EdHuamani Avatar answered Oct 07 '22 09:10

EdHuamani