adguard-home-manager/lib/screens/settings/customization/theme_mode_button.dart

91 lines
3 KiB
Dart
Raw Normal View History

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;
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,
this.disabled
2022-10-26 14:26:09 +02:00
}) : super(key: key);
@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);
final Color greyIconColor = Theme.of(context).brightness == Brightness.light
? const Color.fromRGBO(130, 130, 130, 1)
: const Color.fromRGBO(100, 100, 100, 1);
2022-10-26 14:26:09 +02:00
return Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(16),
child: InkWell(
onTap: disabled == null || disabled == false
? () => onChanged(value)
: null,
2022-10-26 14:26:09 +02:00
borderRadius: BorderRadius.circular(16),
child: AnimatedContainer(
padding: const EdgeInsets.all(10),
width: 150,
height: 150,
duration: const Duration(milliseconds: 200),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: value == selected
? disabled == null || disabled == false
? Theme.of(context).primaryColor
: greyBackgroundColor
: disabled == null || disabled == false
? Theme.of(context).primaryColor.withOpacity(0.1)
: greyBackgroundColor,
2022-10-26 14:26:09 +02:00
border: Border.all(
color: disabled == null || disabled == false
? Theme.of(context).primaryColor
: greyBackgroundColor
2022-10-26 14:26:09 +02:00
)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(
icon,
color: value == selected
? disabled == null || disabled == false
? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white
: greyIconColor
: disabled == null || disabled == false
? null
: greyIconColor,
2022-10-26 14:26:09 +02:00
size: 30,
),
Text(
label,
style: TextStyle(
color: value == selected
? disabled == null || disabled == false
? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white
: greyIconColor
: disabled == null || disabled == false
? null
: greyIconColor,
2022-10-26 14:26:09 +02:00
fontSize: 18
),
)
],
),
),
),
);
}
}