manager-app/lib/Components/switch_input_container.dart
2026-07-17 15:20:41 +02:00

94 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import '../constants.dart';
class SwitchInputContainer extends StatefulWidget {
final bool? isChecked;
final IconData? icon;
final String label;
final String? subtitle;
final ValueChanged<bool> onChanged;
final double fontSize;
const SwitchInputContainer({
Key? key,
this.isChecked,
this.icon,
required this.label,
this.subtitle,
required this.onChanged,
this.fontSize = 18
}) : super(key: key);
@override
_SwitchInputContainerState createState() => _SwitchInputContainerState();
}
class _SwitchInputContainerState extends State<SwitchInputContainer> {
bool? isChecked;
@override
void initState() {
setState(() {
isChecked = widget.isChecked;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
child: Row(
children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: Row(
children: [
if (widget.icon != null)
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(
widget.icon,
color: kPrimaryColor,
size: 25.0,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
widget.label,
style: TextStyle(fontSize: widget.fontSize, fontWeight: FontWeight.w300)
),
if (widget.subtitle != null)
Padding(
padding: const EdgeInsets.only(top: 2),
child: Text(
widget.subtitle!,
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
),
],
),
],
)
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Switch(
value: isChecked ?? false,
activeThumbColor: kPrimaryColor,
onChanged: (bool value) {
setState(() {
isChecked = value;
});
widget.onChanged(value);
},
),
),
],
),
);
}
}