74 lines
1.9 KiB
Dart
74 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../globals.dart';
|
|
|
|
class ReflexTextFormField extends StatefulWidget {
|
|
final String? initialValue;
|
|
final ValueChanged<String>? onChanged;
|
|
final FormFieldValidator<String>? validator;
|
|
final bool obscureText;
|
|
final TextInputType keyboardType;
|
|
final String? label;
|
|
final TextEditingController? controller;
|
|
|
|
const ReflexTextFormField({
|
|
Key? key,
|
|
this.initialValue,
|
|
this.onChanged,
|
|
this.validator,
|
|
this.obscureText = false,
|
|
this.keyboardType = TextInputType.text,
|
|
this.label,
|
|
this.controller,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_ReflexTextFormFieldState createState() => _ReflexTextFormFieldState();
|
|
}
|
|
|
|
class _ReflexTextFormFieldState extends State<ReflexTextFormField> {
|
|
final FocusNode _focusNode = FocusNode();
|
|
late TextEditingController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = widget.controller ?? TextEditingController(text: widget.initialValue);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_focusNode.dispose();
|
|
if (widget.controller == null) {
|
|
_controller.dispose();
|
|
}
|
|
super.dispose();
|
|
}
|
|
|
|
void _requestFocus() {
|
|
setState(() {
|
|
FocusScope.of(context).requestFocus(_focusNode);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextFormField(
|
|
controller: _controller,
|
|
focusNode: _focusNode,
|
|
onTap: _requestFocus,
|
|
onChanged: widget.onChanged,
|
|
obscureText: widget.obscureText,
|
|
keyboardType: widget.keyboardType,
|
|
validator: widget.validator,
|
|
decoration: InputDecoration(
|
|
focusedBorder: const UnderlineInputBorder(
|
|
borderSide: BorderSide(color: Globals.RP_PRIMARY_COLOR, width: 2.0),
|
|
),
|
|
labelText: widget.label,
|
|
labelStyle: TextStyle(color:
|
|
_focusNode.hasFocus ? Globals.RP_PRIMARY_COLOR : Colors.black
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |