Skip to content

Commit 307ac6d

Browse files
committed
feat: add hidden property on input
1 parent 722e85a commit 307ac6d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/src/components/input.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Input with Tools implements Component<String> {
1515
final String answer;
1616
final String? placeholder;
1717
final bool secure;
18+
final bool hidden;
1819
late final List<Sequence> exitMessage;
1920
String value = '';
2021
String? errorMessage;
@@ -31,6 +32,7 @@ class Input with Tools implements Component<String> {
3132
required this.answer,
3233
this.placeholder,
3334
this.secure = false,
35+
this.hidden = false,
3436
Result Function(String value)? validate,
3537
List<Sequence>? exitMessage,
3638
}) {
@@ -120,8 +122,11 @@ class Input with Tools implements Component<String> {
120122
}
121123
}
122124

123-
String generateValue() =>
124-
secure ? value.replaceAll(RegExp(r'.'), '*') : value;
125+
String generateValue() => secure
126+
? value.replaceAll(RegExp(r'.'), '*')
127+
: !hidden
128+
? value
129+
: '';
125130

126131
void render() async {
127132
final buffer = StringBuffer();
@@ -131,9 +136,8 @@ class Input with Tools implements Component<String> {
131136
SetStyles.reset,
132137
Print(' $answer '),
133138
SetStyles(Style.foreground(Color.brightBlack)),
134-
Print(value.isEmpty && errorMessage == null
135-
? placeholder ?? generateValue()
136-
: generateValue()),
139+
Print(
140+
value.isEmpty && errorMessage == null ? placeholder ?? generateValue() : generateValue()),
137141
SetStyles.reset,
138142
]);
139143

0 commit comments

Comments
 (0)