cofounderella/lib/components/my_textfield.dart

68 lines
1.7 KiB
Dart
Raw Permalink Normal View History

2024-04-29 14:36:25 +02:00
import 'package:flutter/material.dart';
class MyTextField extends StatefulWidget {
2024-04-29 14:36:25 +02:00
final String hintText;
final bool obscureText;
2024-04-29 14:36:25 +02:00
final TextEditingController controller;
final FocusNode? focusNode;
2024-04-29 14:36:25 +02:00
const MyTextField({
super.key,
required this.hintText,
required this.obscureText,
2024-04-29 14:36:25 +02:00
required this.controller,
this.focusNode,
2024-04-29 14:36:25 +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(
obscureText: _visibleText,
controller: widget.controller,
focusNode: widget.focusNode,
2024-04-29 14:36:25 +02:00
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.tertiary),
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.primary),
),
filled: true,
hintText: widget.hintText,
suffixIcon: widget.obscureText
? IconButton(
icon: Icon(
_visibleText ? Icons.visibility : Icons.visibility_off,
),
onPressed: _toggleObscureText,
)
: null,
),
2024-04-29 14:36:25 +02:00
),
);
}
}