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

@@ -15,29 +15,29 @@ class ColorItem extends StatelessWidget {
required this.color,
required this.numericValue,
required this.selectedValue,
required this.onChanged
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: index == 0
? const EdgeInsets.only(top: 10, right: 10, bottom: 10)
: index == total-1
? const EdgeInsets.only(top: 10, bottom: 10, left: 10)
: const EdgeInsets.all(10),
? const EdgeInsets.only(top: 10, right: 10, bottom: 10)
: index == total - 1
? const EdgeInsets.only(top: 10, bottom: 10, left: 10)
: const EdgeInsets.all(10),
child: Material(
borderRadius: BorderRadius.circular(50),
child: InkWell(
onTap: () => onChanged(numericValue),
borderRadius: BorderRadius.circular(50),
overlayColor: const MaterialStatePropertyAll(Colors.grey),
overlayColor: const WidgetStatePropertyAll(Colors.grey),
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(50)
borderRadius: BorderRadius.circular(50),
),
child: AnimatedOpacity(
opacity: numericValue == selectedValue ? 1 : 0,
@@ -54,4 +54,4 @@ class ColorItem extends StatelessWidget {
),
);
}
}
}

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,
),
)
),
],
),
),
);
}
}
}