2022-10-19 15:33:15 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class CustomSwitchListTile extends StatelessWidget {
|
|
|
|
final bool value;
|
|
|
|
final void Function(bool) onChanged;
|
|
|
|
final String title;
|
|
|
|
final String? subtitle;
|
2022-10-23 04:50:12 +02:00
|
|
|
final bool? disabled;
|
2023-04-14 01:40:40 +02:00
|
|
|
final EdgeInsets? padding;
|
2024-02-07 19:46:35 +01:00
|
|
|
final IconData? leadingIcon;
|
2022-10-19 15:33:15 +02:00
|
|
|
|
|
|
|
const CustomSwitchListTile({
|
2024-02-07 19:46:35 +01:00
|
|
|
super.key,
|
2022-10-19 15:33:15 +02:00
|
|
|
required this.value,
|
|
|
|
required this.onChanged,
|
|
|
|
required this.title,
|
2022-10-23 04:50:12 +02:00
|
|
|
this.disabled,
|
2022-10-19 15:33:15 +02:00
|
|
|
this.subtitle,
|
2024-02-07 19:46:35 +01:00
|
|
|
this.padding,
|
|
|
|
this.leadingIcon,
|
|
|
|
});
|
2022-10-19 15:33:15 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
2022-10-23 04:50:12 +02:00
|
|
|
onTap: disabled != null && disabled == true
|
|
|
|
? null
|
|
|
|
: () => onChanged(!value),
|
2022-10-19 15:33:15 +02:00
|
|
|
child: Padding(
|
2023-04-14 01:40:40 +02:00
|
|
|
padding: padding ?? const EdgeInsets.only(
|
2022-11-05 03:56:04 +01:00
|
|
|
top: 12, left: 16, right: 18, bottom: 16
|
2022-10-19 15:33:15 +02:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2024-02-07 19:46:35 +01:00
|
|
|
if (leadingIcon != null) ...[
|
|
|
|
Icon(
|
|
|
|
leadingIcon,
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
],
|
2022-11-05 03:56:04 +01:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-10-19 15:33:15 +02:00
|
|
|
title,
|
2022-10-23 04:50:12 +02:00
|
|
|
style: TextStyle(
|
2022-10-19 15:33:15 +02:00
|
|
|
fontSize: 16,
|
2022-10-23 04:50:12 +02:00
|
|
|
color: disabled != null && disabled == true
|
2022-11-05 01:09:09 +01:00
|
|
|
? Theme.of(context).colorScheme.onSurface.withOpacity(0.38)
|
|
|
|
: Theme.of(context).colorScheme.onSurface,
|
2022-10-19 15:33:15 +02:00
|
|
|
),
|
|
|
|
),
|
2022-11-05 03:56:04 +01:00
|
|
|
if (subtitle != null) ... [
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width-110,
|
|
|
|
child: Text(
|
|
|
|
subtitle!,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
color: disabled != null && disabled == true
|
|
|
|
? Theme.of(context).listTileTheme.textColor!.withOpacity(0.38)
|
|
|
|
: Theme.of(context).listTileTheme.textColor
|
|
|
|
),
|
2022-10-19 15:33:15 +02:00
|
|
|
),
|
|
|
|
),
|
2022-11-05 03:56:04 +01:00
|
|
|
]
|
|
|
|
],
|
|
|
|
),
|
2022-10-19 15:33:15 +02:00
|
|
|
),
|
2022-11-05 03:56:04 +01:00
|
|
|
const SizedBox(width: 16),
|
2022-10-19 15:33:15 +02:00
|
|
|
Switch(
|
|
|
|
value: value,
|
2022-10-23 04:50:12 +02:00
|
|
|
onChanged: disabled != null && disabled == true
|
|
|
|
? null
|
|
|
|
: onChanged,
|
2022-10-19 15:33:15 +02:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|