Code improvements
This commit is contained in:
@@ -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 {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user