2024-04-29 14:36:25 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-06-18 22:02:46 +02:00
|
|
|
class MyTextField extends StatefulWidget {
|
2024-04-29 14:36:25 +02:00
|
|
|
final String hintText;
|
2024-04-30 19:25:16 +02:00
|
|
|
final bool obscureText;
|
2024-04-29 14:36:25 +02:00
|
|
|
final TextEditingController controller;
|
2024-04-30 19:25:16 +02:00
|
|
|
final FocusNode? focusNode;
|
2024-04-29 14:36:25 +02:00
|
|
|
|
|
|
|
const MyTextField({
|
|
|
|
super.key,
|
|
|
|
required this.hintText,
|
2024-04-30 19:25:16 +02:00
|
|
|
required this.obscureText,
|
2024-04-29 14:36:25 +02:00
|
|
|
required this.controller,
|
2024-04-30 19:25:16 +02:00
|
|
|
this.focusNode,
|
2024-04-29 14:36:25 +02:00
|
|
|
});
|
|
|
|
|
2024-06-18 22:02:46 +02:00
|
|
|
@override
|
|
|
|
State<MyTextField> createState() => _MyTextFieldState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyTextFieldState extends State<MyTextField> {
|
|
|
|
late bool _visibleText;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_visibleText = widget.obscureText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _toggleObscureText() {
|
|
|
|
setState(() {
|
|
|
|
_visibleText = !_visibleText;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-29 14:36:25 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Padding(
|
2024-06-18 15:01:38 +02:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 25.0, vertical: 8),
|
2024-04-29 14:36:25 +02:00
|
|
|
child: TextField(
|
2024-06-18 22:02:46 +02:00
|
|
|
obscureText: _visibleText,
|
|
|
|
controller: widget.controller,
|
|
|
|
focusNode: widget.focusNode,
|
2024-04-29 14:36:25 +02:00
|
|
|
decoration: InputDecoration(
|
2024-06-18 02:24:42 +02:00
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
borderSide:
|
|
|
|
BorderSide(color: Theme.of(context).colorScheme.tertiary),
|
|
|
|
),
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide:
|
|
|
|
BorderSide(color: Theme.of(context).colorScheme.primary),
|
|
|
|
),
|
|
|
|
filled: true,
|
2024-06-18 22:02:46 +02:00
|
|
|
hintText: widget.hintText,
|
|
|
|
suffixIcon: widget.obscureText
|
|
|
|
? IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
_visibleText ? Icons.visibility : Icons.visibility_off,
|
|
|
|
),
|
|
|
|
onPressed: _toggleObscureText,
|
|
|
|
)
|
|
|
|
: null,
|
2024-06-18 02:24:42 +02:00
|
|
|
),
|
2024-04-29 14:36:25 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|