import 'package:wanisclient/config/custom_text.dart'; import 'package:wanisclient/utils/colors.dart'; import 'package:flutter/material.dart'; import 'package:flutter_lucide/flutter_lucide.dart'; import 'package:provider/provider.dart'; import '../config/language/language_enum.dart'; import '../providers/language_provider.dart'; class ProfileChoiceCard extends StatelessWidget { final String text; final IconData icon; final bool isDelete; const ProfileChoiceCard({ super.key, required this.text, required this.icon, this.isDelete = false, }); @override Widget build(BuildContext context) { final languageProvider = context.watch(); final isArabic = languageProvider.currentLangCode == Language.ar; return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Icon(icon, color:text=="Delete Account"? AppNewColors.deleteAccountColor: AppNewColors.black), const SizedBox(width: 11), Txt( text: text, style: TextStyle( fontWeight: FontWeight.w600, fontSize: 15, fontFamily: isArabic ? "Readex_Pro" : 'Inter', color:text=="Delete Account"? AppNewColors.deleteAccountColor: AppNewColors.black, ), ), ], ), if(text!="Delete Account") Icon( isArabic ? LucideIcons.chevron_left : LucideIcons.chevron_right, color: AppNewColors.grayTxtColor, ), ], ); } } class CustomSwitch extends StatefulWidget { final bool value; final ValueChanged? onChanged; final Color? activeColor; final Color? inactiveColor; final Color? thumbColor; final IconData? activeIcon; final IconData? inactiveIcon; final double? width; final double? height; final Duration animationDuration; final bool isReadOnly; // ✅ NEW const CustomSwitch({ Key? key, required this.value, this.onChanged, this.activeColor, this.inactiveColor, this.thumbColor, this.activeIcon, this.inactiveIcon, this.width, this.height, this.animationDuration = const Duration(milliseconds: 200), this.isReadOnly = false, // ✅ default false }) : super(key: key); @override State createState() => _CustomSwitchState(); } class _CustomSwitchState extends State with SingleTickerProviderStateMixin { late AnimationController _animationController; late Animation _animation; @override void initState() { super.initState(); _animationController = AnimationController( duration: widget.animationDuration, vsync: this, ); _animation = Tween( begin: 0.0, end: 1.0, ).animate(CurvedAnimation( parent: _animationController, curve: Curves.easeInOut, )); if (widget.value) { _animationController.forward(); } } @override void didUpdateWidget(CustomSwitch oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.value != widget.value) { if (widget.value) { _animationController.forward(); } else { _animationController.reverse(); } } } @override void dispose() { _animationController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final switchWidth = widget.width ?? 60.0; final switchHeight = widget.height ?? 32.0; final thumbSize = switchHeight - 4; return GestureDetector( onTap: widget.isReadOnly ? null // ✅ disable toggle when read-only : (widget.onChanged != null ? () => widget.onChanged!(!widget.value) : null), child: AnimatedBuilder( animation: _animation, builder: (context, child) { return Container( width: switchWidth, height: switchHeight, decoration: BoxDecoration( borderRadius: BorderRadius.circular(switchHeight / 2), color: widget.isReadOnly ? AppNewColors.black.withOpacity(.8) // ✅ read-only color : Color.lerp( widget.inactiveColor ?? Colors.grey.shade300, widget.activeColor ?? const Color(0xFF7C3AED), _animation.value, ), ), child: Stack( children: [ AnimatedPositioned( duration: widget.animationDuration, curve: Curves.easeInOut, left: widget.value ? switchWidth - thumbSize - 2 : 2, top: 2, child: Container( width: thumbSize, height: thumbSize, decoration: BoxDecoration( shape: BoxShape.circle, color: widget.thumbColor ?? Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.1), blurRadius: 4, offset: const Offset(0, 2), ), ], ), child: widget.activeIcon != null || widget.inactiveIcon != null ? Icon( widget.value ? (widget.activeIcon ?? LucideIcons.sun) : (widget.inactiveIcon ?? LucideIcons.moon), size: thumbSize * 0.5, color: Colors.black54, ) : null, ), ), ], ), ); }, ), ); } } // Profile choice card with switch option Widget profileChoiceCardWithSwitch({ required String text, required bool switchValue, required ValueChanged onSwitchChanged, IconData? icon, bool isArabic = false, BuildContext? context, bool isReadOnly = false, // ✅ NEW }) { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Row( children: [ if (icon != null) ...[ Icon( icon, color: Colors.black, // AppNewColors.black ), const SizedBox(width: 11), ], Txt(text: text, style: TextStyle( fontWeight: FontWeight.w600, fontSize: 15, fontFamily: isArabic ? "Readex_Pro" : 'Inter', color: Colors.black, // AppNewColors.black ), ), ], ), CustomSwitch( value: switchValue, onChanged: isReadOnly ? null : onSwitchChanged, // ✅ disable if read-only activeColor: const Color(0xFF7C3AED), // Purple color from image inactiveColor: Colors.grey.shade300, activeIcon: LucideIcons.sun, inactiveIcon: LucideIcons.moon, width: 60, height: 32, isReadOnly: isReadOnly, // ✅ pass here ), ], ); }