优化
This commit is contained in:
78
client/flutter/lib/widgets/custom_input.dart
Normal file
78
client/flutter/lib/widgets/custom_input.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sales_chat/theme/app_theme.dart';
|
||||
|
||||
class CustomInput extends StatefulWidget {
|
||||
final String label;
|
||||
final String? hint;
|
||||
final TextEditingController? controller;
|
||||
final bool obscureText;
|
||||
final TextInputType? keyboardType;
|
||||
final IconData? prefixIcon;
|
||||
final IconData? suffixIcon;
|
||||
final VoidCallback? onSuffixTap;
|
||||
final String? Function(String?)? validator;
|
||||
final void Function(String)? onSubmitted;
|
||||
final bool enabled;
|
||||
|
||||
const CustomInput({
|
||||
super.key,
|
||||
required this.label,
|
||||
this.hint,
|
||||
this.controller,
|
||||
this.obscureText = false,
|
||||
this.keyboardType,
|
||||
this.prefixIcon,
|
||||
this.suffixIcon,
|
||||
this.onSuffixTap,
|
||||
this.validator,
|
||||
this.onSubmitted,
|
||||
this.enabled = true,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CustomInput> createState() => _CustomInputState();
|
||||
}
|
||||
|
||||
class _CustomInputState extends State<CustomInput> {
|
||||
late bool _obscureText;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_obscureText = widget.obscureText;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
controller: widget.controller,
|
||||
obscureText: _obscureText,
|
||||
keyboardType: widget.keyboardType,
|
||||
validator: widget.validator,
|
||||
onFieldSubmitted: widget.onSubmitted,
|
||||
enabled: widget.enabled,
|
||||
decoration: InputDecoration(
|
||||
labelText: widget.label,
|
||||
hintText: widget.hint,
|
||||
prefixIcon: widget.prefixIcon != null ? Icon(widget.prefixIcon) : null,
|
||||
suffixIcon: widget.suffixIcon != null
|
||||
? IconButton(
|
||||
icon: Icon(widget.suffixIcon),
|
||||
onPressed: widget.onSuffixTap ?? (widget.obscureText ? _toggleObscure : null),
|
||||
)
|
||||
: (widget.obscureText
|
||||
? IconButton(
|
||||
icon: Icon(_obscureText ? Icons.visibility_off : Icons.visibility),
|
||||
onPressed: _toggleObscure,
|
||||
)
|
||||
: null),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _toggleObscure() {
|
||||
setState(() {
|
||||
_obscureText = !_obscureText;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user