import 'package:wanisclient/config/AppSnackbar.dart'; import 'package:wanisclient/providers/language_provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import '../config/custom_text.dart'; import '../utils/colors.dart'; class PromoCodeInput extends StatefulWidget { final void Function(String value) onApply; final VoidCallback onDontHave; const PromoCodeInput({ Key? key, required this.onApply, required this.onDontHave, }) : super(key: key); @override State createState() => _PromoCodeInputState(); } class _PromoCodeInputState extends State { final TextEditingController _promoCodeController = TextEditingController(); @override void dispose() { // 2. Dispose of the controller when the widget is removed from the widget tree. _promoCodeController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(25.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Promo Code Label const Txt( text: "Promo code", style: TextStyle( fontSize: 25, fontWeight: FontWeight.bold, color: Colors.black, ), ), const SizedBox(height: 8), // Input Field TextFormField( controller: _promoCodeController, maxLength: 15, decoration: InputDecoration( hintText: languageSingleton.translate("your promo code"), hintStyle: TextStyle(color: Colors.grey.shade500), prefixIcon: Padding( padding: const EdgeInsets.all(12.0), child: SvgPicture.asset( 'assets/icons/voucher.svg', // Adjust path as needed width: 20, color: Colors.grey.shade500, ), ), contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: Colors.grey, width: 1), ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: const BorderSide(color:AppNewColors.primaryColor, width: 2), ), filled: true, fillColor: Colors.grey.shade100, ), ), const SizedBox(height: 12), // Buttons Row Row( children: [ // "I Don't Have" Button Expanded( child: OutlinedButton( onPressed: widget.onDontHave, style: OutlinedButton.styleFrom( padding: const EdgeInsets.symmetric(vertical: 14), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), side: const BorderSide(color: AppNewColors.backgroundPurpleColor2), backgroundColor: AppNewColors.backgroundPurpleColor2, // ← add bg ), child: const Txt( text: "I Don't have", style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, color: AppColors.primaryColor, ), ), ), ), const SizedBox(width: 12), // "Apply" Button Expanded( child: ElevatedButton( onPressed: () { final value = _promoCodeController.text.trim(); if (value.isNotEmpty) { widget.onApply(value); } else { AppSnackbar.showInfo("Info", "Please enter a promo code."); } }, style: ElevatedButton.styleFrom( backgroundColor: AppNewColors.primaryBtnColor, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 14), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), child: const Txt( text: "Apply", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), ), ), ], ), ], ), ); } }