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;
|
2022-10-19 15:33:15 +02:00
|
|
|
|
|
|
|
const CustomSwitchListTile({
|
|
|
|
Key? key,
|
|
|
|
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,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@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(
|
|
|
|
padding: const EdgeInsets.only(
|
2022-11-05 01:09:09 +01:00
|
|
|
top: 12, left: 24, right: 12, bottom: 12
|
2022-10-19 15:33:15 +02:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width-110,
|
|
|
|
child: Text(
|
|
|
|
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
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (subtitle != null) ... [
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width-110,
|
|
|
|
child: Text(
|
|
|
|
subtitle!,
|
2022-10-21 11:26:14 +02:00
|
|
|
style: TextStyle(
|
2022-10-19 15:33:15 +02:00
|
|
|
fontSize: 14,
|
2022-10-23 04:50:12 +02:00
|
|
|
color: disabled != null && disabled == true
|
2022-11-05 02:35:35 +01:00
|
|
|
? Theme.of(context).listTileTheme.textColor!.withOpacity(0.38)
|
|
|
|
: Theme.of(context).listTileTheme.textColor
|
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
|
|
|
activeColor: Theme.of(context).primaryColor,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|