From bb62783fc754d8566b1d1ea93611dc7479fc75f8 Mon Sep 17 00:00:00 2001 From: Tkko Date: Thu, 6 Jun 2024 10:12:44 +0400 Subject: [PATCH] Fixed date in CHANGELOG.md --- CHANGELOG.md | 2 +- lib/src/pinput_state.dart | 55 +++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d1750..147018a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -#### 5.0.0 · 9/04/2024 +#### 5.0.0 · 6/06/2024 - Implemented Pinput.builder to build custom Pinput fields - Migrated deprecated imperative apply of Flutter's Gradle plugins example app - Removed smart_auth dependency which was responsible for SMS autofill (Not everyone might need it and it was causing some issues) diff --git a/lib/src/pinput_state.dart b/lib/src/pinput_state.dart index af3b354..27bbee0 100644 --- a/lib/src/pinput_state.dart +++ b/lib/src/pinput_state.dart @@ -15,7 +15,8 @@ class _PinputState extends State late bool forcePressEnabled; @override - final GlobalKey editableTextKey = GlobalKey(); + final GlobalKey editableTextKey = + GlobalKey(); @override bool get selectionEnabled => widget.toolbarEnabled; @@ -37,8 +38,8 @@ class _PinputState extends State String? get _errorText => widget.errorText ?? _validatorErrorText; bool get _canRequestFocus { - final NavigationMode mode = - MediaQuery.maybeOf(context)?.navigationMode ?? NavigationMode.traditional; + final NavigationMode mode = MediaQuery.maybeOf(context)?.navigationMode ?? + NavigationMode.traditional; switch (mode) { case NavigationMode.traditional: return isEnabled && widget.useNativeKeyboard; @@ -47,10 +48,12 @@ class _PinputState extends State } } - TextEditingController get _effectiveController => widget.controller ?? _controller!.value; + TextEditingController get _effectiveController => + widget.controller ?? _controller!.value; @protected - FocusNode get effectiveFocusNode => widget.focusNode ?? (_focusNode ??= FocusNode()); + FocusNode get effectiveFocusNode => + widget.focusNode ?? (_focusNode ??= FocusNode()); @protected bool get hasError => widget.forceErrorState || _validatorErrorText != null; @@ -71,7 +74,8 @@ class _PinputState extends State @override void initState() { super.initState(); - _gestureDetectorBuilder = _PinputSelectionGestureDetectorBuilder(state: this); + _gestureDetectorBuilder = + _PinputSelectionGestureDetectorBuilder(state: this); if (widget.controller == null) { _createLocalController(); _recentControllerValue = TextEditingValue.empty; @@ -106,7 +110,8 @@ class _PinputState extends State } void _handleTextEditingControllerChanges() { - final textChanged = _recentControllerValue.text != _effectiveController.value.text; + final textChanged = + _recentControllerValue.text != _effectiveController.value.text; _recentControllerValue = _effectiveController.value; if (textChanged) { _onChanged(pin); @@ -204,7 +209,8 @@ class _PinputState extends State TextSelection selection, SelectionChangedCause? cause, ) { - _effectiveController.selection = TextSelection.collapsed(offset: pin.length); + _effectiveController.selection = + TextSelection.collapsed(offset: pin.length); switch (Theme.of(context).platform) { case TargetPlatform.iOS: @@ -213,7 +219,8 @@ class _PinputState extends State case TargetPlatform.windows: case TargetPlatform.fuchsia: case TargetPlatform.android: - if (cause == SelectionChangedCause.longPress || cause == SelectionChangedCause.drag) { + if (cause == SelectionChangedCause.longPress || + cause == SelectionChangedCause.drag) { _editableText?.bringIntoView(selection.extent); } break; @@ -293,7 +300,8 @@ class _PinputState extends State forcePressEnabled = false; textSelectionControls ??= cupertinoDesktopTextSelectionHandleControls; handleDidGainAccessibilityFocus = () { - if (!effectiveFocusNode.hasFocus && effectiveFocusNode.canRequestFocus) { + if (!effectiveFocusNode.hasFocus && + effectiveFocusNode.canRequestFocus) { effectiveFocusNode.requestFocus(); } }; @@ -311,7 +319,8 @@ class _PinputState extends State forcePressEnabled = false; textSelectionControls ??= desktopTextSelectionHandleControls; handleDidGainAccessibilityFocus = () { - if (!effectiveFocusNode.hasFocus && effectiveFocusNode.canRequestFocus) { + if (!effectiveFocusNode.hasFocus && + effectiveFocusNode.canRequestFocus) { effectiveFocusNode.requestFocus(); } }; @@ -419,14 +428,17 @@ class _PinputState extends State onSelectionChanged: _handleSelectionChanged, onSelectionHandleTapped: _handleSelectionHandleTapped, readOnly: widget.readOnly || !isEnabled || !widget.useNativeKeyboard, - selectionControls: widget.toolbarEnabled ? textSelectionControls : null, - keyboardAppearance: widget.keyboardAppearance ?? Theme.of(context).brightness, + selectionControls: + widget.toolbarEnabled ? textSelectionControls : null, + keyboardAppearance: + widget.keyboardAppearance ?? Theme.of(context).brightness, ), ), ); } - MouseCursor get _effectiveMouseCursor => MaterialStateProperty.resolveAs( + MouseCursor get _effectiveMouseCursor => + MaterialStateProperty.resolveAs( widget.mouseCursor ?? MaterialStateMouseCursor.textable, { if (!isEnabled) MaterialState.disabled, @@ -492,7 +504,8 @@ class _PinputState extends State [effectiveFocusNode, _effectiveController], ), builder: (BuildContext context, Widget? child) { - final shouldHideErrorContent = widget.validator == null && widget.errorText == null; + final shouldHideErrorContent = + widget.validator == null && widget.errorText == null; if (shouldHideErrorContent) return onlyFields(); @@ -515,7 +528,8 @@ class _PinputState extends State @protected bool get hasFocus { final isLastPin = selectedIndex == widget.length; - return effectiveFocusNode.hasFocus || (!widget.useNativeKeyboard && !isLastPin); + return effectiveFocusNode.hasFocus || + (!widget.useNativeKeyboard && !isLastPin); } @protected @@ -534,7 +548,8 @@ class _PinputState extends State child: Text( _errorText!, style: widget.errorTextStyle ?? - theme.textTheme.titleMedium?.copyWith(color: theme.colorScheme.error), + theme.textTheme.titleMedium + ?.copyWith(color: theme.colorScheme.error), ), ); } @@ -545,11 +560,13 @@ class _PinputState extends State // AutofillClient implementation start. @override - void autofill(TextEditingValue newEditingValue) => _editableText!.autofill(newEditingValue); + void autofill(TextEditingValue newEditingValue) => + _editableText!.autofill(newEditingValue); @override TextInputConfiguration get textInputConfiguration { - final List? autofillHints = widget.autofillHints?.toList(growable: false); + final List? autofillHints = + widget.autofillHints?.toList(growable: false); final AutofillConfiguration autofillConfiguration = autofillHints != null ? AutofillConfiguration( uniqueIdentifier: autofillId,