Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply rounded borders to expanded ExpansionTile in Flutter?

Tags:

flutter

What I am trying to do is to apply rounded edges to the entire tile even when the Container inside children is open, in the same way as when it is collapsed. I tried to apply the style through its Container using BoxDecoration, but it gives me error. I don't know how to proceed because ExpansionTile unlike ListTile doesn't have an attribute for the shape.

Collapsed tile with rounded bordes

Expanded tile with right angles borders

class DocumentTile extends StatelessWidget {
  final Document document;

  const DocumentTile({Key key, this.document}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Card(
      margin: const EdgeInsets.only(top: 12, right: 30),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(8.0),
      ),
      color: AppColors.lbBlue.materialColor,
      child: Container(
        width: MediaQuery.of(context).size.width * 0.83,
        child: ExpansionTile(
          tilePadding: const EdgeInsets.only(left: 40.0, right: 30.0),
          backgroundColor: AppColors.nsIconGrey.materialColor,
          trailing: Container(
            width: MediaQuery.of(context).size.width * 0.49,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Container(
                      width: 0.5,
                      height: 50,
                      color: Colors.white,
                      margin: const EdgeInsets.only(right: 16.0),
                    ),
                    Text(
                        '${DateTime.fromMicrosecondsSinceEpoch(document.creationDate * 1000)}',
                        style: tileDate),
                  ],
                ),
                Row(
                  children: [
                    Container(
                        margin: const EdgeInsets.only(right: 6),
                        height: 35,
                        width: 35,
                        decoration: BoxDecoration(
                          color: AppColors.tagIcon.materialColor,
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: Center(
                          child: Text(
                            '${document.tags[0].acronym}',
                            style: documentTag,
                          ),
                        )),
                    Container(
                        height: 35,
                        width: 35,
                        decoration: BoxDecoration(
                          color: AppColors.addTagIcon.materialColor,
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: IconButton(
                          icon: Icon(Icons.add, color: Colors.white),
                          iconSize: 25,
                          padding: const EdgeInsets.all(5.5),
                          onPressed: () {},
                        )),
                  ],
                ),
                Row(
                  children: [
                    Container(
                        margin: const EdgeInsets.only(right: 6),
                        height: 35,
                        width: 35,
                        decoration: BoxDecoration(
                          color: AppColors.sPdIcon.materialColor,
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: IconButton(
                          icon: Icon(Icons.more_vert, color: Colors.white),
                          iconSize: 25,
                          padding: const EdgeInsets.all(5.5),
                          onPressed: () {},
                        )),
                    Container(
                        margin: const EdgeInsets.only(right: 6),
                        height: 35,
                        width: 35,
                        decoration: BoxDecoration(
                          color: AppColors.sPdIcon.materialColor,
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: IconButton(
                          icon: Icon(Icons.share_outlined, color: Colors.white),
                          iconSize: 20,
                          padding: const EdgeInsets.all(5.5),
                          onPressed: () {},
                        )),
                    Container(
                        height: 35,
                        width: 35,
                        decoration: BoxDecoration(
                          color: AppColors.sPdIcon.materialColor,
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: IconButton(
                          icon: Icon(Icons.arrow_forward, color: Colors.white),
                          iconSize: 25,
                          padding: const EdgeInsets.all(5.5),
                          onPressed: () {
                            Navigator.pushNamed(context, '/documentDetail',
                                arguments: document.id);
                          },
                        )),
                  ],
                ),
              ],
            ),
          ),
          subtitle: Text(
            '${document.abstract0}',
            style: tileDescription,
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
          ),
          title: Text(
            '${document.title}',
            style: tileTitle,
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
          ),
          children: [
            Container(
              width: double.maxFinite,
              padding: const EdgeInsets.only(
                  left: 40.0, right: 30.0, top: 20, bottom: 20),
              color: Color(0xFF2A3141),
              child: Text(
                '${document.content}',
                style: TextStyle(
                    color: AppColors.darkerText2.materialColor,
                    fontSize: 10,
                    fontWeight: FontWeight.w300),
                maxLines: 3,
                overflow: TextOverflow.ellipsis,
              ),
            )
          ],
        ),
      ),
    );
  }
}

like image 874
Bruner4 Avatar asked Dec 16 '20 21:12

Bruner4


People also ask

How do you give a round border to a container in flutter?

If you want border for all the corners you can use like bellow. Container( decoration: BoxDecoration( color: Colors. white, borderRadius: BorderRadius.

How do you customize expansion tiles in flutter?

You need to implement it in your code respectively: Create a new dart file called expansion_title_demo. dart inside the lib folder. In this screen, we will create a list with the help of a list view builder in which the expansion tile widget will be used and initialize the list data into the expansion tile widget.

What is expansion Tile widget in flutter?

A single-line ListTile with a trailing button that expands or collapses the tile to reveal or hide the children. H ello friends, I will talk about my new blog on Expansion Tile Widget In Flutter. We will also implement a demo of the Expansion Tile Widget, and describes its properties, and how to use them in your flutter applications.

How to show a widget with rounded borders in flutter?

Want to show a widget with rounded borders in Flutter? Just wrap your widget with a DecoratedBox and give it a decoration like this: DecoratedBox( decoration: BoxDecoration( color: Colors.blue, borderRadius: const BorderRadius.all(Radius.circular(16)), // alternatively, do this: // borderRadius: BorderRadius.circular (16), ) child: someWidget, )

What is flexfit in flutter?

fit: This property controls how the child widget fills the available space. There are two options given by flutter, the first is FlexFit. tight which sets the child to fill the space available to it and the second is FlexFit.loose which allows the child widget to be as large as the available space.

What is Google’s expansion tile card?

But it uses the style used by Google itself in its products to raise a tile. It can be called a better version of the Flutter’s ExpansionTileCard. In this article, we will look into the process of implementing the Expansion Tile Card in a Flutter application by building a simple flutter app.


1 Answers

Just wrap it with a ClipRRect widget, it allows you to set a border radius for any widget.

like image 75
Miguel Ruivo Avatar answered Oct 13 '22 20:10

Miguel Ruivo