Code improvements

This commit is contained in:
Juan Gilsanz Polo
2025-04-03 22:26:14 +02:00
parent 7982644c23
commit 93ebb1de40
17 changed files with 114 additions and 107 deletions

View File

@@ -9,44 +9,42 @@ class ThemeModeButton extends StatelessWidget {
final bool? disabled;
const ThemeModeButton({
Key? key,
super.key,
required this.icon,
required this.value,
required this.selected,
required this.label,
required this.onChanged,
this.disabled
}) : super(key: key);
this.disabled,
});
@override
Widget build(BuildContext context) {
final Color greyBackgroundColor = Theme.of(context).brightness == Brightness.light
?const Color.fromRGBO(200, 200, 200, 1)
:const Color.fromRGBO(50, 50, 50, 1);
? const Color.fromRGBO(200, 200, 200, 1)
: const Color.fromRGBO(50, 50, 50, 1);
final Color greyIconColor = Theme.of(context).brightness == Brightness.light
? const Color.fromRGBO(130, 130, 130, 1)
: const Color.fromRGBO(100, 100, 100, 1);
? const Color.fromRGBO(130, 130, 130, 1)
: const Color.fromRGBO(100, 100, 100, 1);
return ElevatedButton(
onPressed: disabled == null || disabled == false
? () => onChanged(value)
: null,
onPressed: disabled == null || disabled == false ? () => onChanged(value) : null,
style: ButtonStyle(
elevation: MaterialStateProperty.all(0),
shape: MaterialStateProperty.all(
elevation: WidgetStateProperty.all(0),
shape: WidgetStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
)
),
),
backgroundColor: MaterialStateProperty.all(
backgroundColor: WidgetStateProperty.all(
value == selected
? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary
: greyBackgroundColor
: disabled == null || disabled == false
? Theme.of(context).colorScheme.surfaceVariant
: greyBackgroundColor,
)
? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary
: greyBackgroundColor
: disabled == null || disabled == false
? Theme.of(context).colorScheme.surfaceContainerHighest
: greyBackgroundColor,
),
),
child: AnimatedContainer(
width: 118,
@@ -59,30 +57,34 @@ class ThemeModeButton extends StatelessWidget {
Icon(
icon,
color: value == selected
? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5 ? Colors.black : Colors.white
: greyIconColor
: disabled == null || disabled == false
? Theme.of(context).colorScheme.primary
: greyIconColor,
? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5
? Colors.black
: Colors.white
: greyIconColor
: disabled == null || disabled == false
? Theme.of(context).colorScheme.primary
: greyIconColor,
size: 30,
),
Text(
label,
style: TextStyle(
color: value == selected
? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5 ? Colors.black : Colors.white
: greyIconColor
? disabled == null || disabled == false
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5
? Colors.black
: Colors.white
: greyIconColor
: disabled == null || disabled == false
? Theme.of(context).colorScheme.primary
: greyIconColor,
fontSize: 18
? Theme.of(context).colorScheme.primary
: greyIconColor,
fontSize: 18,
),
)
),
],
),
),
);
}
}
}