import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:intl/intl.dart'; import 'package:material_symbols_icons/material_symbols_icons.dart'; class BlockCardScreen extends StatefulWidget { const BlockCardScreen({super.key}); @override State createState() => _BlockCardScreen(); } class _BlockCardScreen extends State { final _formKey = GlobalKey(); final _cardController = TextEditingController(); final _cvvController = TextEditingController(); final _expiryController = TextEditingController(); final _phoneController = TextEditingController(); Future _pickExpiryDate() async { final now = DateTime.now(); final selectedDate = await showDatePicker( context: context, initialDate: now, firstDate: now, lastDate: DateTime(now.year + 10), ); if (selectedDate != null) { _expiryController.text = DateFormat('dd/MM/yyyy').format(selectedDate); } } void _blockCard() { if (_formKey.currentState?.validate() ?? false) { // Call your backend logic here final snackBar = SnackBar( content: const Text('Card has been blocked'), action: SnackBarAction( label: 'X', onPressed: () { // Just close the SnackBar }, textColor: Colors.white, ), backgroundColor: Colors.black, behavior: SnackBarBehavior.floating, ); ScaffoldMessenger.of(context).showSnackBar(snackBar); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( leading: IconButton( icon: const Icon(Symbols.arrow_back_ios_new), onPressed: () { Navigator.pop(context); }, ), title: const Text( 'Block Card', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w500), ), centerTitle: false, actions: [ Padding( padding: const EdgeInsets.only(right: 10.0), child: CircleAvatar( backgroundColor: Colors.grey[200], radius: 20, child: SvgPicture.asset( 'assets/images/avatar_male.svg', width: 40, height: 40, fit: BoxFit.cover, ), ), ), ], ), body: Padding( padding: const EdgeInsets.all(10.0), child: Form( key: _formKey, child: ListView( children: [ const SizedBox(height: 10), TextFormField( controller: _cardController, decoration: const InputDecoration( labelText: 'Card Number', border: OutlineInputBorder(), isDense: true, filled: true, fillColor: Colors.white, enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black), ), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 2), ), ), keyboardType: TextInputType.number, textInputAction: TextInputAction.next, validator: (value) => value != null && value.length == 16 ? null : 'Enter valid card number', ), const SizedBox(height: 24), Row( children: [ Expanded( child: TextFormField( controller: _cvvController, decoration: const InputDecoration( labelText: 'CVV', border: OutlineInputBorder(), isDense: true, filled: true, fillColor: Colors.white, enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black), ), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 2), ), ), keyboardType: TextInputType.number, textInputAction: TextInputAction.next, obscureText: true, validator: (value) => value != null && value.length == 3 ? null : 'CVV must be 3 digits', ), ), const SizedBox(width: 16), Expanded( child: TextFormField( controller: _expiryController, readOnly: true, onTap: _pickExpiryDate, decoration: const InputDecoration( labelText: 'Expiry Date', suffixIcon: Icon(Icons.calendar_today), border: OutlineInputBorder(), isDense: true, filled: true, fillColor: Colors.white, enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black), ), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 2), ), ), validator: (value) => value != null && value.isNotEmpty ? null : 'Select expiry date', ), ), ], ), const SizedBox(height: 24), TextFormField( controller: _phoneController, decoration: const InputDecoration( labelText: 'Phone', prefixIcon: Icon(Icons.phone), border: OutlineInputBorder(), isDense: true, filled: true, fillColor: Colors.white, enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black), ), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 2), ), ), textInputAction: TextInputAction.done, keyboardType: TextInputType.phone, validator: (value) => value != null && value.length >= 10 ? null : 'Enter valid phone number', ), const SizedBox(height: 45), Align( alignment: Alignment.center, child: SizedBox( width: 250, child: ElevatedButton( onPressed: _blockCard, style: ElevatedButton.styleFrom( shape: const StadiumBorder(), padding: const EdgeInsets.symmetric(vertical: 16), backgroundColor: Colors.blue[900], foregroundColor: Colors.white, ), child: const Text('Block'), ), ), ), ], ), ), ), ); } }