Search code examples
flutteruitabbarcontroller

In Tab Bar I use label indicator I add Tab Bar indicator border radius how I can give it radius


I add tab bar when I use indicator size as a label I show label indicator topright & topleft curve border

TabBar( 
indicatorColor: mainColor,
 /*indicator: BoxDecoration(
 //borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
               ),*/
 indicatorWeight: 5,
  indicatorSize: TabBarIndicatorSize.tab,`your text`
)

Solution

  • Ty to use CustomTabIndicator as below... Give indicator:CustomTabIndicator()

    class CustomTabIndicator extends Decoration {
          final double radius;
          final Color color;
          final double indicatorHeight;
        
          const CustomTabIndicator({
            this.radius = 15,
            this.indicatorHeight = 10,
            this.color = Colors.black,
          });
        
          @override
          _CustomPainter createBoxPainter([VoidCallback? onChanged]) {
            return _CustomPainter(
              this,
              onChanged,
            );
          }
        }
        
        class _CustomPainter extends BoxPainter {
          final CustomTabIndicator decoration;
        
          _CustomPainter(
              this.decoration,
              VoidCallback? onChanged,
              ) : super(onChanged);
        
          @override
          void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
            assert(configuration.size != null);
        
            final Paint paint = Paint();
            double xAxisPos = offset.dx + configuration.size!.width/2;
            double yAxisPos = offset.dy + configuration.size!.height - 15/2;
        
            RRect fullRect = RRect.fromRectAndCorners(
              Rect.fromCenter(
                center: Offset(xAxisPos, yAxisPos),
                width: configuration.size!.width ,
                height: 15,
              ),
              topLeft: Radius.circular(15),
              bottomLeft: Radius.circular(15),
            );
        
            canvas.drawRRect(fullRect, paint);
          }
        }