59 lines
1.8 KiB
Dart
59 lines
1.8 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
|
||
|
|
import '../../core/theme/design_tokens.dart';
|
||
|
|
|
||
|
|
class AppToggleSwitch extends StatelessWidget {
|
||
|
|
const AppToggleSwitch({
|
||
|
|
super.key,
|
||
|
|
required this.value,
|
||
|
|
required this.onChanged,
|
||
|
|
this.activeBackgroundColor,
|
||
|
|
this.inactiveBackgroundColor,
|
||
|
|
this.activeBorderColor,
|
||
|
|
this.inactiveBorderColor,
|
||
|
|
});
|
||
|
|
|
||
|
|
final bool value;
|
||
|
|
final ValueChanged<bool> onChanged;
|
||
|
|
final Color? activeBackgroundColor;
|
||
|
|
final Color? inactiveBackgroundColor;
|
||
|
|
final Color? activeBorderColor;
|
||
|
|
final Color? inactiveBorderColor;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return GestureDetector(
|
||
|
|
onTap: () => onChanged(!value),
|
||
|
|
child: Container(
|
||
|
|
width: AppSpacing.xxl + AppSpacing.xl,
|
||
|
|
height: AppSpacing.xl + AppSpacing.xs,
|
||
|
|
padding: const EdgeInsets.all(AppSpacing.xs / 2),
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
color: value
|
||
|
|
? (activeBackgroundColor ?? AppColors.blue100)
|
||
|
|
: (inactiveBackgroundColor ?? AppColors.surfaceTertiary),
|
||
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
||
|
|
border: Border.all(
|
||
|
|
color: value
|
||
|
|
? (activeBorderColor ?? AppColors.blue300)
|
||
|
|
: (inactiveBorderColor ?? AppColors.borderSecondary),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
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),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|