2025-11-21 15:28:46 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
|
2025-12-04 17:32:42 +01:00
|
|
|
class CustomTextField extends StatefulWidget {
|
|
|
|
|
final bool? showPassword;
|
2025-11-21 15:28:46 +01:00
|
|
|
final bool numeric;
|
|
|
|
|
final String hint;
|
|
|
|
|
final String label;
|
|
|
|
|
final int? lines;
|
|
|
|
|
final ValueChanged<String>? onChanged;
|
|
|
|
|
final int? length;
|
2025-12-04 17:32:42 +01:00
|
|
|
final TextEditingController? controller;
|
2025-11-21 15:28:46 +01:00
|
|
|
|
2025-12-04 17:32:42 +01:00
|
|
|
const CustomTextField({
|
2025-11-21 15:28:46 +01:00
|
|
|
super.key,
|
|
|
|
|
this.showPassword,
|
|
|
|
|
this.numeric = false,
|
|
|
|
|
this.hint = '',
|
|
|
|
|
this.label = '',
|
|
|
|
|
this.lines,
|
|
|
|
|
this.length,
|
|
|
|
|
this.onChanged,
|
2025-12-04 17:32:42 +01:00
|
|
|
this.controller,
|
2025-11-21 15:28:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
2025-12-03 15:28:10 +01:00
|
|
|
State<CustomTextField> createState() => CustomTextFieldState();
|
2025-11-21 15:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-04 17:32:42 +01:00
|
|
|
class CustomTextFieldState extends State<CustomTextField> {
|
|
|
|
|
late bool _showPassword;
|
2025-11-21 15:28:46 +01:00
|
|
|
@override
|
2025-12-04 17:32:42 +01:00
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_showPassword = widget.showPassword ?? true;
|
|
|
|
|
}
|
2025-11-21 15:28:46 +01:00
|
|
|
|
2025-12-04 17:32:42 +01:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-12-03 15:28:10 +01:00
|
|
|
return Column(
|
|
|
|
|
spacing: 8,
|
|
|
|
|
children: [
|
2025-12-04 17:32:42 +01:00
|
|
|
if (widget.label.isNotEmpty)
|
|
|
|
|
Align(
|
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
|
child: Text(
|
|
|
|
|
widget.label,
|
|
|
|
|
style: const TextStyle(fontSize: 14, letterSpacing: 0),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-12-03 15:28:10 +01:00
|
|
|
TextFormField(
|
2025-12-09 10:08:36 +01:00
|
|
|
controller: widget.controller,
|
2025-12-04 17:32:42 +01:00
|
|
|
keyboardType: widget.numeric
|
|
|
|
|
? TextInputType.number
|
|
|
|
|
: TextInputType.text,
|
|
|
|
|
obscureText: !_showPassword,
|
|
|
|
|
enableSuggestions: _showPassword,
|
|
|
|
|
autocorrect: !_showPassword,
|
|
|
|
|
style: const TextStyle(color: Color(0xFF4B4B4B)),
|
|
|
|
|
inputFormatters: widget.numeric
|
|
|
|
|
? <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly]
|
|
|
|
|
: const <TextInputFormatter>[],
|
2025-12-03 15:28:10 +01:00
|
|
|
decoration: InputDecoration(
|
|
|
|
|
counterText: "",
|
|
|
|
|
hintText: widget.hint,
|
2025-12-04 17:32:42 +01:00
|
|
|
border: const OutlineInputBorder(
|
2025-12-03 15:28:10 +01:00
|
|
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
|
|
|
borderSide: BorderSide(color: Color(0xFF4B4B4B)),
|
2025-12-04 17:32:42 +01:00
|
|
|
gapPadding: 16,
|
2025-12-03 15:28:10 +01:00
|
|
|
),
|
2025-12-04 17:32:42 +01:00
|
|
|
suffixIcon: widget.showPassword != null
|
|
|
|
|
? IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
_showPassword ? Icons.visibility_off : Icons.visibility,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
_showPassword = !_showPassword;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: null,
|
2025-12-03 15:28:10 +01:00
|
|
|
),
|
|
|
|
|
minLines: widget.lines ?? 1,
|
|
|
|
|
maxLines: widget.lines ?? 1,
|
|
|
|
|
maxLength: widget.length,
|
2025-12-04 17:32:42 +01:00
|
|
|
onChanged: widget.onChanged,
|
|
|
|
|
),
|
2025-12-03 15:28:10 +01:00
|
|
|
],
|
2025-11-21 15:28:46 +01:00
|
|
|
);
|
|
|
|
|
}
|
2025-12-04 17:32:42 +01:00
|
|
|
}
|