@@ -171,6 +171,15 @@ class PinCodeTextField extends StatefulWidget {
171171 /// Use external [AutoFillGroup]
172172 final bool useExternalAutoFillGroup;
173173
174+ /// Displays a hint or placeholder in the field if it's value is empty.
175+ /// It only appears if it's not null. Single character is recommended.
176+ final String ? hintCharacter;
177+
178+ /// the style of the [hintCharacter] , default is [fontSize: 20, fontWeight: FontWeight.bold]
179+ /// and it also uses the [textStyle] 's properties
180+ /// [TextStyle.color] is [Colors.grey]
181+ final TextStyle ? hintStyle;
182+
174183 PinCodeTextField ({
175184 Key ? key,
176185 required this .appContext,
@@ -220,6 +229,8 @@ class PinCodeTextField extends StatefulWidget {
220229 this .cursorColor,
221230 this .cursorWidth = 2 ,
222231 this .cursorHeight,
232+ this .hintCharacter,
233+ this .hintStyle,
223234
224235 /// Default for [AutofillGroup]
225236 this .onAutoFillDisposeAction = AutofillContextAction .commit,
@@ -271,6 +282,14 @@ class _PinCodeTextFieldState extends State<PinCodeTextField>
271282 fontWeight: FontWeight .bold,
272283 ).merge (widget.textStyle);
273284
285+ TextStyle get _hintStyle => _textStyle
286+ .copyWith (
287+ color: _pinTheme.disabledColor,
288+ )
289+ .merge (widget.hintStyle);
290+
291+ bool get _hintAvailable => widget.hintCharacter != null ;
292+
274293 @override
275294 void initState () {
276295 // if (!kReleaseMode) {
@@ -490,10 +509,18 @@ class _PinCodeTextFieldState extends State<PinCodeTextField>
490509 }
491510 }
492511
512+ if (_inputList[index! ].isEmpty && _hintAvailable) {
513+ return Text (
514+ widget.hintCharacter! ,
515+ key: ValueKey (_inputList[index]),
516+ style: _hintStyle,
517+ );
518+ }
519+
493520 return Text (
494- widget.obscureText && _inputList[index! ].isNotEmpty && showObscured
521+ widget.obscureText && _inputList[index].isNotEmpty && showObscured
495522 ? widget.obscuringCharacter
496- : _inputList[index! ],
523+ : _inputList[index],
497524 key: ValueKey (_inputList[index]),
498525 style: _textStyle,
499526 );
0 commit comments