@@ -38,6 +38,9 @@ class ThemedTab extends StatelessWidget {
3838 /// This information is only used when the tab is a child of a [ThemedTabView]
3939 final Widget child;
4040
41+ /// [style] is the style of the tab
42+ final ThemedTabStyle style;
43+
4144 /// [ThemedTab] is a tab for the [TabBar] widget
4245 const ThemedTab ({
4346 super .key,
@@ -51,34 +54,75 @@ class ThemedTab extends StatelessWidget {
5154 this .padding = const EdgeInsets .all (10 ),
5255 this .color,
5356 this .child = const SizedBox (),
57+ this .style = ThemedTabStyle .filledTonal,
5458 }) : assert (labelText != null || label != null );
5559
60+ ThemedTab overrideStyle (ThemedTabStyle newStyle) {
61+ return ThemedTab (
62+ key: key,
63+ labelText: labelText,
64+ label: label,
65+ iconSize: iconSize,
66+ leading: leading,
67+ leadingIcon: leadingIcon,
68+ trailing: trailing,
69+ trailingIcon: trailingIcon,
70+ padding: padding,
71+ color: color,
72+ child: child,
73+ style: newStyle,
74+ );
75+ }
76+
5677 @override
5778 Widget build (BuildContext context) {
58- return Padding (
79+ final primary = Theme .of (context).colorScheme.primary;
80+ Color backgroundColor = color ?? DefaultTextStyle .of (context).style.color ?? primary;
81+ final bool redMatch = primary.r == backgroundColor.r;
82+ final bool greenMatch = primary.g == backgroundColor.g;
83+ final bool blueMatch = primary.b == backgroundColor.b;
84+
85+ final isActive = redMatch && greenMatch && blueMatch;
86+
87+ return AnimatedContainer (
88+ duration: const Duration (milliseconds: 200 ),
5989 padding: padding,
60- child: Row (
61- children: [
62- if (leading != null || leadingIcon != null ) ...[
63- leading ??
64- Icon (
65- leadingIcon! ,
66- size: iconSize,
67- color: color,
90+ decoration: style == ThemedTabStyle .filledTonal
91+ ? BoxDecoration (
92+ color: isActive ? backgroundColor.withAlpha ((255 * 0.2 ).toInt ()) : Colors .transparent,
93+ borderRadius: BorderRadius .circular (8 ),
94+ )
95+ : null ,
96+ child: Padding (
97+ padding: const EdgeInsets .symmetric (horizontal: 10 ),
98+ child: RichText (
99+ text: TextSpan (
100+ children: [
101+ if (leading != null || leadingIcon != null ) ...[
102+ WidgetSpan (
103+ alignment: PlaceholderAlignment .middle,
104+ child: leading ?? Icon (leadingIcon! , size: iconSize, color: backgroundColor),
105+ ),
106+ const WidgetSpan (child: SizedBox (width: 10 )),
107+ ],
108+ if (label != null ) ...[
109+ WidgetSpan (child: label! ),
110+ ] else ...[
111+ TextSpan (
112+ text: labelText,
113+ style: Theme .of (context).textTheme.bodyMedium? .copyWith (color: backgroundColor),
68114 ),
69- const SizedBox (width: 10 ),
70- ],
71- label ?? Text (labelText ?? '' , style: TextStyle (color: color)),
72- if (trailing != null || trailingIcon != null ) ...[
73- const SizedBox (width: 10 ),
74- trailing ??
75- Icon (
76- trailingIcon! ,
77- size: iconSize,
78- color: color,
115+ ],
116+ if (trailing != null || trailingIcon != null ) ...[
117+ const WidgetSpan (child: SizedBox (width: 10 )),
118+ WidgetSpan (
119+ alignment: PlaceholderAlignment .middle,
120+ child: trailing ?? Icon (trailingIcon! , size: iconSize, color: backgroundColor),
79121 ),
80- ],
81- ],
122+ ],
123+ ],
124+ ),
125+ ),
82126 ),
83127 );
84128 }
0 commit comments