import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:material_symbols_icons/material_symbols_icons.dart'; class CardPinSetScreen extends StatefulWidget { const CardPinSetScreen({super.key}); @override State createState() => _CardPinSetScreen(); } class _CardPinSetScreen extends State { final _formKey = GlobalKey(); final _pinController = TextEditingController(); final _confirmPinController = TextEditingController(); void _submit() { if (_formKey.currentState!.validate()) { // Handle PIN submission logic here final snackBar = SnackBar( content: const Text('PIN set successfully'), action: SnackBarAction( label: 'X', onPressed: () { // Just close the SnackBar }, textColor: Colors.white, ), backgroundColor: Colors.black, behavior: SnackBarBehavior.floating, ); ScaffoldMessenger.of(context).showSnackBar(snackBar); } } @override void dispose() { _pinController.dispose(); _confirmPinController.dispose(); super.dispose(); } @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( 'Card PIN', 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(16.0), child: Form( key: _formKey, child: Column( children: [ TextFormField( controller: _pinController, obscureText: true, decoration: const InputDecoration( labelText: 'Enter new PIN', 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) { if (value == null || value.isEmpty) { return 'Please enter new PIN'; } if (value.length < 4) { return 'PIN must be at least 4 digits'; } return null; }, ), const SizedBox(height: 24), TextFormField( controller: _confirmPinController, obscureText: true, decoration: const InputDecoration( labelText: 'Enter Again', 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.done, validator: (value) { if (value != _pinController.text) { return 'PINs do not match'; } return null; }, ), const SizedBox(height: 45), Align( alignment: Alignment.center, child: SizedBox( width: 250, child: ElevatedButton( onPressed: _submit, style: ElevatedButton.styleFrom( shape: const StadiumBorder(), padding: const EdgeInsets.symmetric(vertical: 16), backgroundColor: Colors.blue[900], foregroundColor: Colors.white, ), child: const Text('Submit'), ), ), ), ], ), ), ), ); } }