How to change ripple effect to not overlap with the tab's shape?

Viewed 214

The image below is an example of when a tab is long pressed but it shows an undesirable rectangle-shaped grey ripple effect.

long pressed active tab and long pressed inactive tab

How do I change its shape so that it has the same shape as the tab?

Here is my current code:

build method:

@override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        body: CustomScrollView(
          slivers: [
            SliverAppBar(
              title: Text('Task n\' Note'),
              pinned: true,
              floating: true,
              foregroundColor: Colors.black,
              backgroundColor: Colors.white,
              bottom: TabBar(
                unselectedLabelColor: Colors.blueAccent,
                indicatorSize: TabBarIndicatorSize.label,
                indicator: BoxDecoration(
                    borderRadius: BorderRadius.circular(25.0),
                    color: Colors.blueAccent),
                tabs: [
                  _buildTab('Tasks'),
                  _buildTab('Notes'),
                ],
              ),
            )
          ],
        ),
      ),
    );

_buildTab method:

Widget _buildTab(String title) {
    return Tab(
      child: Align(
        alignment: Alignment.center,
        child: Text(title),
      ),
    );
  }
1 Answers

I suggest you use the InkWell widget and its property customBorder. Make sure that the Material, InkWell and InkWell's child have the same shape.

Here is an example how that could look like.

enter image description here

Material(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
    child: InkWell(
        customBorder: shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
        onTap: () {},
        ...
        child:  ListTile(shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(20)))
    ),
)
Related