Fix focus on mobile when navigating away and coming back to field, added readme pizaz

This commit is contained in:
Nathan Anderson
2023-11-21 11:46:42 -07:00
parent dd52ffb398
commit a8e571ca7b
4 changed files with 39 additions and 26 deletions
+1 -1
View File
@@ -261,7 +261,7 @@ enum CardDetailsValidState {
invalidZip,
}
/// Enum of supported U.S. Card Providers
/// Enum of supported Card Providers
enum CardProviderID {
americanExpress,
dinersClub,
+12 -5
View File
@@ -323,14 +323,15 @@ class CardTextFieldState extends State<CardTextField> {
},
// Enable scrolling on mobile and if its narrow (not all fields visible)
onHorizontalDragUpdate: (details) {
const minOffset = 0.0;
final maxOffset = _horizontalScrollController.position.maxScrollExtent;
if (!_isMobile || isWideFormat) return;
final newOffset = _horizontalScrollController.offset - details.delta.dx;
final max = _horizontalScrollController.position.maxScrollExtent;
if (newOffset < -30.0) {
_horizontalScrollController.jumpTo(-30.0);
} else if (newOffset > max + 30.0) {
_horizontalScrollController.jumpTo(max + 30.0);
if (newOffset < minOffset) {
_horizontalScrollController.jumpTo(minOffset);
} else if (newOffset > maxOffset) {
_horizontalScrollController.jumpTo(maxOffset);
} else {
_horizontalScrollController.jumpTo(newOffset);
}
@@ -773,6 +774,12 @@ class CardTextFieldState extends State<CardTextField> {
_setValidationState(null);
}
// If field tapped, and has focus, dismiss focus
if (_currentStep == step && _hasFocus()) {
FocusManager.instance.primaryFocus?.unfocus();
return;
}
setState(() {
_currentStep = step;
});