diff --git a/lib/src/pinput.dart b/lib/src/pinput.dart index 76d39a2..4db26cd 100644 --- a/lib/src/pinput.dart +++ b/lib/src/pinput.dart @@ -104,6 +104,7 @@ class Pinput extends StatefulWidget { this.onAppPrivateCommand, this.mouseCursor, this.forceErrorState = false, + this.showErrorWhenFocused = false, this.errorText, this.validator, this.errorBuilder, @@ -159,6 +160,7 @@ class Pinput extends StatefulWidget { this.onAppPrivateCommand, this.mouseCursor, this.forceErrorState = false, + this.showErrorWhenFocused = false, this.validator, this.pinputAutovalidateMode = PinputAutovalidateMode.onSubmit, this.scrollPadding = const EdgeInsets.all(20), @@ -390,6 +392,9 @@ class Pinput extends StatefulWidget { /// If true [errorPinTheme] will be applied and [errorText] will be displayed under the Pinput final bool forceErrorState; + /// If true, the error will also be displayed in the focused state. Otherwise the error is not displayed in the focused state. + final bool showErrorWhenFocused; + /// Text displayed under the Pinput if Pinput is invalid final String? errorText; diff --git a/lib/src/pinput_state.dart b/lib/src/pinput_state.dart index 30b453d..10870ff 100644 --- a/lib/src/pinput_state.dart +++ b/lib/src/pinput_state.dart @@ -331,7 +331,7 @@ class _PinputState extends State enabled: isEnabled, validator: _validator, initialValue: _effectiveController.text, - builder: (FormFieldState field) { + builder: (field) { return MouseRegion( cursor: _effectiveMouseCursor, onEnter: (PointerEnterEvent event) => _handleHover(true), @@ -354,7 +354,10 @@ class _PinputState extends State child: Stack( alignment: Alignment.topCenter, children: [ - _buildEditable(textSelectionControls, field), + // the editable need to be the full size, otherwise the focus is not correct when getting the renderbox from the focus + Positioned.fill( + child: _buildEditable(textSelectionControls, field), + ), _buildFields(), ], ), @@ -543,7 +546,10 @@ class _PinputState extends State } @protected - bool get showErrorState => hasError && (!hasFocus || widget.forceErrorState); + bool get showErrorState { + return hasError && + ((!hasFocus || (hasFocus && widget.showErrorWhenFocused)) || widget.forceErrorState); + } Widget _buildError() { if (showErrorState) {