mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
feat: add obscureText handling and add suffixIcon parameter to getTextFieldInputDecoration
This commit is contained in:
@@ -21,15 +21,36 @@ class EnvAuthField extends StatefulWidget {
|
|||||||
this.readOnly = false,
|
this.readOnly = false,
|
||||||
this.isObscureText = false,
|
this.isObscureText = false,
|
||||||
this.infoText,
|
this.infoText,
|
||||||
required this.initialValue});
|
this.initialValue = ""});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<EnvAuthField> createState() => _AuthFieldState();
|
State<EnvAuthField> createState() => _AuthFieldState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AuthFieldState extends State<EnvAuthField> {
|
class _AuthFieldState extends State<EnvAuthField> {
|
||||||
|
late bool _obscureText;
|
||||||
|
late String _currentValue;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_currentValue = widget.initialValue ?? "";
|
||||||
|
if (_currentValue.contains("{{")) {
|
||||||
|
_obscureText = false;
|
||||||
|
} else {
|
||||||
|
_obscureText = widget.isObscureText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _toggleVisibility() {
|
||||||
|
setState(() {
|
||||||
|
_obscureText = !_obscureText;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
debugPrint(widget.initialValue);
|
||||||
return AutofillGroup(
|
return AutofillGroup(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
@@ -58,11 +79,21 @@ class _AuthFieldState extends State<EnvAuthField> {
|
|||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
EnvironmentTriggerField(
|
EnvironmentTriggerField(
|
||||||
keyId: "auth-${widget.title ?? widget.hintText}-${Random.secure()}",
|
keyId: "auth-${widget.title ?? widget.hintText}-${Random.secure()}",
|
||||||
onChanged: widget.onChanged,
|
onChanged: (value) {
|
||||||
initialValue: widget.initialValue ?? "",
|
setState(() {
|
||||||
|
_currentValue = value;
|
||||||
|
// Update obscure text based on whether the current value contains env vars
|
||||||
|
if (value.contains("{{")) {
|
||||||
|
_obscureText = false;
|
||||||
|
} else {
|
||||||
|
_obscureText = widget.isObscureText;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
widget.onChanged?.call(value);
|
||||||
|
},
|
||||||
|
initialValue: widget.initialValue,
|
||||||
readOnly: widget.readOnly,
|
readOnly: widget.readOnly,
|
||||||
// TODO: Needs some new implementation
|
obscureText: _obscureText,
|
||||||
// obscureText: widget.isObscureText,
|
|
||||||
style: kCodeStyle.copyWith(
|
style: kCodeStyle.copyWith(
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
fontSize: Theme.of(context).textTheme.bodyMedium?.fontSize,
|
fontSize: Theme.of(context).textTheme.bodyMedium?.fontSize,
|
||||||
@@ -72,6 +103,17 @@ class _AuthFieldState extends State<EnvAuthField> {
|
|||||||
hintText: widget.hintText,
|
hintText: widget.hintText,
|
||||||
isDense: true,
|
isDense: true,
|
||||||
contentPadding: kIsMobile ? kPh6b12 : null,
|
contentPadding: kIsMobile ? kPh6b12 : null,
|
||||||
|
// null when initial text contains env vars
|
||||||
|
suffixIcon: (widget.isObscureText &&
|
||||||
|
!_currentValue.contains("{{"))
|
||||||
|
? IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscureText ? Icons.visibility_off : Icons.visibility,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
onPressed: _toggleVisibility,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ InputDecoration getTextFieldInputDecoration(
|
|||||||
TextStyle? hintTextStyle,
|
TextStyle? hintTextStyle,
|
||||||
double? hintTextFontSize,
|
double? hintTextFontSize,
|
||||||
Color? hintTextColor,
|
Color? hintTextColor,
|
||||||
|
Widget? suffixIcon,
|
||||||
EdgeInsetsGeometry? contentPadding,
|
EdgeInsetsGeometry? contentPadding,
|
||||||
Color? focussedBorderColor,
|
Color? focussedBorderColor,
|
||||||
Color? enabledBorderColor,
|
Color? enabledBorderColor,
|
||||||
@@ -21,6 +22,7 @@ InputDecoration getTextFieldInputDecoration(
|
|||||||
fontSize: hintTextFontSize,
|
fontSize: hintTextFontSize,
|
||||||
color: hintTextColor ?? clrScheme.outlineVariant,
|
color: hintTextColor ?? clrScheme.outlineVariant,
|
||||||
),
|
),
|
||||||
|
suffixIcon: suffixIcon,
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
contentPadding: contentPadding ?? kP10,
|
contentPadding: contentPadding ?? kP10,
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
|
|||||||
Reference in New Issue
Block a user