2022-10-26 14:26:09 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class ThemeModeButton extends StatelessWidget {
|
|
|
|
final IconData icon;
|
|
|
|
final int value;
|
|
|
|
final int selected;
|
|
|
|
final String label;
|
|
|
|
final void Function(int) onChanged;
|
2022-10-29 14:22:19 +02:00
|
|
|
final bool? disabled;
|
2022-10-26 14:26:09 +02:00
|
|
|
|
|
|
|
const ThemeModeButton({
|
|
|
|
Key? key,
|
|
|
|
required this.icon,
|
|
|
|
required this.value,
|
|
|
|
required this.selected,
|
|
|
|
required this.label,
|
|
|
|
required this.onChanged,
|
2022-10-29 14:22:19 +02:00
|
|
|
this.disabled
|
2022-10-26 14:26:09 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-29 14:22:19 +02:00
|
|
|
final Color greyBackgroundColor = Theme.of(context).brightness == Brightness.light
|
|
|
|
?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);
|
|
|
|
|
2022-11-05 03:56:04 +01:00
|
|
|
return ElevatedButton(
|
|
|
|
onPressed: disabled == null || disabled == false
|
|
|
|
? () => onChanged(value)
|
|
|
|
: null,
|
|
|
|
style: ButtonStyle(
|
|
|
|
elevation: MaterialStateProperty.all(0),
|
|
|
|
shape: MaterialStateProperty.all(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(30),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
backgroundColor: MaterialStateProperty.all(
|
|
|
|
value == selected
|
|
|
|
? disabled == null || disabled == false
|
2023-01-25 20:51:23 +01:00
|
|
|
? Theme.of(context).colorScheme.primary
|
2022-11-05 03:56:04 +01:00
|
|
|
: greyBackgroundColor
|
|
|
|
: disabled == null || disabled == false
|
2023-01-25 20:51:23 +01:00
|
|
|
? Theme.of(context).colorScheme.surfaceVariant
|
2022-11-05 03:56:04 +01:00
|
|
|
: greyBackgroundColor,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
child: AnimatedContainer(
|
|
|
|
width: 118,
|
|
|
|
height: 150,
|
|
|
|
curve: Curves.easeInOut,
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
icon,
|
|
|
|
color: value == selected
|
|
|
|
? disabled == null || disabled == false
|
2023-01-25 20:51:23 +01:00
|
|
|
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5 ? Colors.black : Colors.white
|
2022-11-05 03:56:04 +01:00
|
|
|
: greyIconColor
|
|
|
|
: disabled == null || disabled == false
|
2023-01-25 20:51:23 +01:00
|
|
|
? Theme.of(context).colorScheme.primary
|
2022-11-05 03:56:04 +01:00
|
|
|
: greyIconColor,
|
|
|
|
size: 30,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
label,
|
|
|
|
style: TextStyle(
|
2022-10-26 14:26:09 +02:00
|
|
|
color: value == selected
|
2022-10-29 14:22:19 +02:00
|
|
|
? disabled == null || disabled == false
|
2023-01-25 20:51:23 +01:00
|
|
|
? Theme.of(context).colorScheme.primary.computeLuminance() > 0.5 ? Colors.black : Colors.white
|
2022-11-05 03:56:04 +01:00
|
|
|
: greyIconColor
|
|
|
|
: disabled == null || disabled == false
|
2023-01-25 20:51:23 +01:00
|
|
|
? Theme.of(context).colorScheme.primary
|
2022-11-05 03:56:04 +01:00
|
|
|
: greyIconColor,
|
|
|
|
fontSize: 18
|
2022-10-26 14:26:09 +02:00
|
|
|
),
|
2022-11-05 03:56:04 +01:00
|
|
|
)
|
|
|
|
],
|
2022-10-26 14:26:09 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|