2026-03-18 13:35:25 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import '../../core/theme/design_tokens.dart';
|
|
|
|
|
|
|
|
|
|
class AppToggleSwitch extends StatelessWidget {
|
|
|
|
|
const AppToggleSwitch({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.value,
|
2026-03-24 12:38:11 +08:00
|
|
|
this.onChanged,
|
2026-03-18 13:35:25 +08:00
|
|
|
this.activeBackgroundColor,
|
|
|
|
|
this.inactiveBackgroundColor,
|
|
|
|
|
this.activeBorderColor,
|
|
|
|
|
this.inactiveBorderColor,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final bool value;
|
2026-03-24 12:38:11 +08:00
|
|
|
final ValueChanged<bool>? onChanged;
|
2026-03-18 13:35:25 +08:00
|
|
|
final Color? activeBackgroundColor;
|
|
|
|
|
final Color? inactiveBackgroundColor;
|
|
|
|
|
final Color? activeBorderColor;
|
|
|
|
|
final Color? inactiveBorderColor;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return GestureDetector(
|
2026-03-24 12:38:11 +08:00
|
|
|
onTap: onChanged == null ? null : () => onChanged!(!value),
|
|
|
|
|
child: Opacity(
|
|
|
|
|
opacity: onChanged == null ? 0.55 : 1,
|
|
|
|
|
child: Container(
|
|
|
|
|
width: AppSpacing.xxl + AppSpacing.xl,
|
|
|
|
|
height: AppSpacing.xl + AppSpacing.xs,
|
|
|
|
|
padding: const EdgeInsets.all(AppSpacing.xs / 2),
|
|
|
|
|
decoration: BoxDecoration(
|
2026-03-18 13:35:25 +08:00
|
|
|
color: value
|
2026-03-24 12:38:11 +08:00
|
|
|
? (activeBackgroundColor ?? AppColors.blue100)
|
|
|
|
|
: (inactiveBackgroundColor ?? AppColors.surfaceTertiary),
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: value
|
|
|
|
|
? (activeBorderColor ?? AppColors.blue300)
|
|
|
|
|
: (inactiveBorderColor ?? AppColors.borderSecondary),
|
|
|
|
|
),
|
2026-03-18 13:35:25 +08:00
|
|
|
),
|
2026-03-24 12:38:11 +08:00
|
|
|
child: AnimatedAlign(
|
|
|
|
|
duration: const Duration(milliseconds: 150),
|
|
|
|
|
alignment: value ? Alignment.centerRight : Alignment.centerLeft,
|
|
|
|
|
child: Container(
|
|
|
|
|
width: AppSpacing.lg + AppSpacing.xs,
|
|
|
|
|
height: AppSpacing.lg + AppSpacing.xs,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
|
|
|
|
border: Border.all(color: AppColors.borderSecondary),
|
|
|
|
|
),
|
2026-03-18 13:35:25 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|