@@ -101,6 +101,20 @@ class ThemedButton extends StatefulWidget {
101101 /// defaults to `8`
102102 final double iconSeparatorSize;
103103
104+ /// [loadingBackgroundColor] is used to set the background color of the loading indicator.
105+ ///
106+ /// By default uses `Colors.transparent` .
107+ final Color ? loadingBackgroundColor;
108+
109+ /// [loadingForegroundColor] is used to set the foreground color of the loading indicator.
110+ ///
111+ /// By default uses the `Theme.of(context).inputDecorationTheme.fillColor`
112+ final Color ? loadingForegroundColor;
113+
114+ /// [legacyLoadingColors] is used to determine if the loading indicator should use the legacy colors.
115+ /// By default, will use `false` .
116+ final bool legacyLoadingColors;
117+
104118 /// [ThemedButton] is a widget that displays a button with a custom label.
105119 const ThemedButton ({
106120 super .key,
@@ -124,6 +138,9 @@ class ThemedButton extends StatefulWidget {
124138 this .height = defaultHeight,
125139 this .iconSize = 22 ,
126140 this .iconSeparatorSize = 8 ,
141+ this .loadingBackgroundColor,
142+ this .loadingForegroundColor,
143+ this .legacyLoadingColors = false ,
127144 }) : assert (label != null || labelText != null , "You must provide a label or labelText, not both or none." ),
128145 assert (height >= 30 , "Height must be greater than 30u" ),
129146 assert (iconSize >= 0 , "Icon size must be greater than 0" ),
@@ -263,6 +280,52 @@ class ThemedButton extends StatefulWidget {
263280 );
264281 }
265282
283+ factory ThemedButton .legacyLoading ({
284+ Widget ? label,
285+ String ? labelText,
286+ IconData ? icon,
287+ VoidCallback ? onTap,
288+ bool isLoading = false ,
289+ Color ? color,
290+ ThemedButtonStyle style = ThemedButtonStyle .filledTonal,
291+ bool isCooldown = false ,
292+ String ? hintText,
293+ double ? width,
294+ bool isDisabled = false ,
295+ Duration cooldownDuration = const Duration (seconds: 5 ),
296+ VoidCallback ? onCooldownFinish,
297+ ThemedTooltipPosition tooltipPosition = ThemedTooltipPosition .bottom,
298+ double fontSize = 14 ,
299+ bool tooltipEnabled = true ,
300+ bool showCooldownRemainingDuration = true ,
301+ double height = ThemedButton .defaultHeight,
302+ double iconSize = 22 ,
303+ double iconSeparatorSize = 8 ,
304+ }) {
305+ return ThemedButton (
306+ label: label,
307+ labelText: labelText,
308+ icon: icon,
309+ onTap: onTap,
310+ isLoading: isLoading,
311+ color: color,
312+ style: style,
313+ isCooldown: isCooldown,
314+ hintText: hintText,
315+ width: width,
316+ isDisabled: isDisabled,
317+ cooldownDuration: cooldownDuration,
318+ onCooldownFinish: onCooldownFinish,
319+ tooltipPosition: tooltipPosition,
320+ fontSize: fontSize,
321+ tooltipEnabled: tooltipEnabled,
322+ showCooldownRemainingDuration: showCooldownRemainingDuration,
323+ height: height,
324+ iconSize: iconSize,
325+ iconSeparatorSize: iconSeparatorSize,
326+ legacyLoadingColors: true ,
327+ );
328+ }
266329 @override
267330 State <ThemedButton > createState () => _ThemedButtonState ();
268331
@@ -379,17 +442,28 @@ class _ThemedButtonState extends State<ThemedButton> {
379442 /// Also, the font color will change depending of the [style] of the button.
380443 TextStyle ? get textStyle => Theme .of (context).textTheme.bodyMedium? .copyWith (fontSize: widget.fontSize);
381444
382- Color get disabledColor => ThemedButton .getDisabledColor (isDark, style);
445+ // Color get disabledColor => ThemedButton.getDisabledColor(isDark, style);
446+ Color get disabledColor => widget.legacyLoadingColors
447+ ? ThemedButton .getDisabledColor (isDark, style)
448+ : (widget.loadingForegroundColor ?? Theme .of (context).inputDecorationTheme.fillColor ?? Colors .grey);
383449
384450 /// [contentColor] is used to know the color of the content of the button.
385451 Color get contentColor => isDisabled ? disabledColor : (widget.color ?? defaultColor);
386452
387453 /// [loadingColor] defines the color of the loading indicator.
388- Color get loadingColor => isDark ? Colors .grey.shade500 : Colors .grey.shade400;
454+ Color get loadingColor => widget.legacyLoadingColors
455+ ? isDark
456+ ? Colors .grey.shade500
457+ : Colors .grey.shade400
458+ : widget.loadingForegroundColor ?? contentColor;
389459
390460 /// [colorOverride] allows to set a new color when the button is loading, on cooldown or disabled.
391461 /// Otherwise, will return `null` .
392- Color ? get colorOverride => isLoading || isCooldown ? disabledColor : null ;
462+ Color ? get colorOverride => isLoading || isCooldown
463+ ? widget.legacyLoadingColors
464+ ? disabledColor
465+ : Colors .transparent
466+ : null ;
393467
394468 /// [iconSize] is used to know the size of the icon.
395469 double get iconSize => widget.iconSize;
@@ -514,9 +588,8 @@ class _ThemedButtonState extends State<ThemedButton> {
514588 /// [_handleHint] is used to handle the hint of the button.
515589 /// This hint is only used when the button is style as any non-FAB style
516590 Widget _handleHint ({required Widget child}) {
517- if (hintText == null ) {
518- return child;
519- }
591+ if (hintText == null ) return child;
592+ if (isLoading || isCooldown) return child;
520593
521594 return ThemedTooltip (
522595 position: widget.tooltipPosition,
@@ -529,9 +602,8 @@ class _ThemedButtonState extends State<ThemedButton> {
529602 /// [_handleTooltip] is used to handle the tooltip of the button when the button is a FAB.
530603 /// This tooltip is only used when the button is style as any FAB style
531604 Widget _handleTooltip ({required Widget child}) {
532- if (! widget.tooltipEnabled) {
533- return child;
534- }
605+ if (! widget.tooltipEnabled) return child;
606+ if (isLoading || isCooldown) return child;
535607
536608 return ThemedTooltip (
537609 position: widget.tooltipPosition,
@@ -1157,8 +1229,8 @@ class _ThemedButtonState extends State<ThemedButton> {
11571229 int remaining = (cooldownDuration.inSeconds * (1 - value)).round () + 1 ;
11581230
11591231 Widget progress = LinearProgressIndicator (
1160- backgroundColor: Colors .transparent,
1161- valueColor : AlwaysStoppedAnimation < Color >( loadingColor) ,
1232+ backgroundColor: widget.loadingBackgroundColor ?? Colors .transparent,
1233+ color : loadingColor,
11621234 value: value,
11631235 );
11641236
@@ -1188,8 +1260,8 @@ class _ThemedButtonState extends State<ThemedButton> {
11881260 children: [
11891261 Positioned .fill (
11901262 child: LinearProgressIndicator (
1191- backgroundColor: Colors .transparent,
1192- valueColor : AlwaysStoppedAnimation < Color >( loadingColor) ,
1263+ backgroundColor: widget.loadingBackgroundColor ?? Colors .transparent,
1264+ color : loadingColor,
11931265 ),
11941266 ),
11951267 ],
0 commit comments