I am trying to create a TabBar which has a gradient underline like in the image below.

I tried to use a BoxDecoration as suggested by earlier posts but it does not exactly display as i want it to.
TabBar(
labelColor: Theme.of(context).primaryColor,
indicator: BoxDecoration(
gradient: LinearGradient(
colors: const [Color(0xFF10C7E0), Color(0xFF00D5C3)],
),
),
tabs: ...,
),
When i try that, what i get is
](https://i.sstatic.net/3UQLN.png)
Someone pointed out that this post is a duplicate of how-to-give-a-gradient-line-in-tab-bar-indicator which was posted 10 months ago. BUT the method illustrated there NO longer works. Yes, i tried it.
what's wrong with this option? (based on code from link)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text('All', style: TextStyle(color: const Color(0xff596173))),
backgroundColor: Colors.white,
centerTitle: true,
bottom: TabBar(
labelColor: const Color(0xff525c6e),
unselectedLabelColor: const Color(0xffacb3bf),
indicatorPadding: EdgeInsets.all(0.0),
indicatorWeight: 4.0,
labelPadding: EdgeInsets.only(left: 0.0, right: 0.0),
indicator: ShapeDecoration(
shape: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.transparent, width: 0, style: BorderStyle.solid)),
gradient: LinearGradient(colors: [Color(0xff0081ff), Color(0xff01ff80)])),
tabs: <Widget>[
Container(
height: 40,
alignment: Alignment.center,
color: Colors.white,
child: Text("Visual"),
),
Container(
height: 40,
alignment: Alignment.center,
color: Colors.white,
child: Text("Tabular"),
),
],
),
),
body: Container(color: Colors.grey[200]),
),
),
);
}
}

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With