Rain/lib/app/ui/settings/widgets/setting_card.dart

108 lines
2.7 KiB
Dart
Raw Normal View History

2023-06-17 20:57:57 +03:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2024-08-12 21:03:35 +03:00
import 'package:iconsax_plus/iconsax_plus.dart';
2023-06-17 20:57:57 +03:00
2023-07-15 21:51:32 +03:00
class SettingCard extends StatelessWidget {
const SettingCard({
2023-06-17 20:57:57 +03:00
super.key,
required this.icon,
required this.text,
2023-07-09 23:41:51 +03:00
this.switcher = false,
this.dropdown = false,
this.info = false,
this.infoSettings = false,
2023-07-15 20:23:36 +03:00
this.elevation,
2023-06-17 20:57:57 +03:00
this.dropdownName,
this.dropdownList,
2025-05-28 17:42:15 +03:00
this.dropdownChange,
2023-06-17 20:57:57 +03:00
this.value,
this.onPressed,
this.onChange,
2023-10-12 11:36:18 +05:30
this.infoWidget,
2023-06-17 20:57:57 +03:00
});
2025-05-28 17:42:15 +03:00
2023-06-17 20:57:57 +03:00
final Widget icon;
final String text;
final bool switcher;
final bool dropdown;
final bool info;
2023-07-09 23:41:51 +03:00
final bool infoSettings;
2023-10-12 11:36:18 +05:30
final Widget? infoWidget;
2023-06-17 20:57:57 +03:00
final String? dropdownName;
final List<String>? dropdownList;
2025-05-28 17:42:15 +03:00
final ValueChanged<String?>? dropdownChange;
2023-06-17 20:57:57 +03:00
final bool? value;
2025-05-28 17:42:15 +03:00
final VoidCallback? onPressed;
final ValueChanged<bool>? onChange;
2023-07-15 20:23:36 +03:00
final double? elevation;
2023-06-17 20:57:57 +03:00
@override
Widget build(BuildContext context) {
2023-07-10 21:33:43 +03:00
return Card(
2023-07-15 20:23:36 +03:00
elevation: elevation ?? 1,
2023-09-29 15:45:50 +03:00
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
2023-07-10 21:33:43 +03:00
child: ListTile(
2025-03-15 23:40:48 +03:00
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
2023-07-10 21:33:43 +03:00
onTap: onPressed,
leading: icon,
title: Text(
text,
style: context.textTheme.titleMedium,
overflow: TextOverflow.visible,
),
2025-05-28 17:42:15 +03:00
trailing: _buildTrailingWidget(context),
),
);
}
Widget _buildTrailingWidget(BuildContext context) {
if (switcher) {
return _buildSwitchWidget();
} else if (dropdown) {
return _buildDropdownWidget();
} else if (info) {
return _buildInfoWidget();
} else {
return const Icon(IconsaxPlusLinear.arrow_right_3, size: 18);
}
}
Widget _buildSwitchWidget() {
return Transform.scale(
scale: 0.8,
child: Switch(value: value!, onChanged: onChange),
);
}
Widget _buildDropdownWidget() {
return DropdownButton<String>(
icon: const Padding(
padding: EdgeInsets.only(left: 7),
child: Icon(IconsaxPlusLinear.arrow_down),
2023-06-17 20:57:57 +03:00
),
2025-05-28 17:42:15 +03:00
iconSize: 15,
alignment: AlignmentDirectional.centerEnd,
borderRadius: const BorderRadius.all(Radius.circular(15)),
underline: Container(),
value: dropdownName,
items: dropdownList!.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(value: value, child: Text(value));
}).toList(),
onChanged: dropdownChange,
2023-06-17 20:57:57 +03:00
);
}
2025-05-28 17:42:15 +03:00
Widget _buildInfoWidget() {
if (infoSettings) {
return Wrap(
children: [
infoWidget!,
const Icon(IconsaxPlusLinear.arrow_right_3, size: 18),
],
);
} else {
return infoWidget!;
}
}
2023-06-17 20:57:57 +03:00
}