adguard-home-manager/lib/widgets/custom_switch_list_tile.dart

79 lines
2.5 KiB
Dart
Raw Normal View History

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;
final bool? disabled;
2022-10-19 15:33:15 +02:00
const CustomSwitchListTile({
Key? key,
required this.value,
required this.onChanged,
required this.title,
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(
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,
style: TextStyle(
2022-10-19 15:33:15 +02:00
fontSize: 16,
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!,
style: TextStyle(
2022-10-19 15:33:15 +02:00
fontSize: 14,
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,
onChanged: disabled != null && disabled == true
? null
: onChanged,
2022-10-19 15:33:15 +02:00
activeColor: Theme.of(context).primaryColor,
)
],
),
),
),
);
}
}