mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
95 lines
2.9 KiB
Dart
95 lines
2.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|
|
|
class ToggleWidget extends StatelessWidget {
|
|
final bool value;
|
|
final String code;
|
|
final String deviceId;
|
|
final String label;
|
|
final String? icon;
|
|
final Widget? labelWidget;
|
|
final Function(dynamic value) onChange;
|
|
final bool showToggle;
|
|
final bool showIcon;
|
|
|
|
const ToggleWidget({
|
|
super.key,
|
|
required this.value,
|
|
required this.code,
|
|
required this.deviceId,
|
|
required this.label,
|
|
required this.onChange,
|
|
this.icon,
|
|
this.labelWidget,
|
|
this.showToggle = true,
|
|
this.showIcon = true,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(20),
|
|
color: ColorsManager.greyColor.withOpacity(0.2),
|
|
border: Border.all(color: ColorsManager.boxDivider),
|
|
),
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 12),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
icon == '-1'
|
|
? const SizedBox(
|
|
height: 60,
|
|
width: 60,
|
|
)
|
|
: ClipOval(
|
|
child: Container(
|
|
height: 60,
|
|
width: 60,
|
|
padding: const EdgeInsets.all(8),
|
|
color: ColorsManager.whiteColors,
|
|
child: SvgPicture.asset(
|
|
icon ?? Assets.lightPulp,
|
|
width: 35,
|
|
height: 35,
|
|
fit: BoxFit.contain,
|
|
),
|
|
)),
|
|
if (showToggle)
|
|
Container(
|
|
height: 20,
|
|
width: 35,
|
|
padding: const EdgeInsets.only(right: 16, top: 10),
|
|
child: CupertinoSwitch(
|
|
value: value,
|
|
activeColor: ColorsManager.dialogBlueTitle,
|
|
onChanged: onChange,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
labelWidget ??
|
|
Text(
|
|
label,
|
|
style: context.textTheme.titleMedium!.copyWith(
|
|
fontWeight: FontWeight.w400,
|
|
color: ColorsManager.blackColor,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|