Skip to content

Commit

Permalink
feat: ✨Added card holder text capitalization feasibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil Totala committed Jan 9, 2025
1 parent 1c62271 commit 9dffbb7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Fixed floating event stream bad state exception [#157](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/157).
- Fixed Gyroscope initialization issue [#173](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/173).
- Fixed Namespace Not Found issue [#176](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/176).
- Added `isCardHolderNameUpperCase` to make card holder text field always accept uppercase[#174](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/174).

# [4.0.1](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/4.0.1)

Expand Down
14 changes: 14 additions & 0 deletions lib/src/credit_card_form.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/src/services/text_formatter.dart';

import '../flutter_credit_card.dart';
import 'masked_text_controller.dart';
import 'utils/constants.dart';
import 'utils/helpers.dart';
import 'utils/typedefs.dart';
import 'utils/validators.dart';

Expand Down Expand Up @@ -35,6 +37,7 @@ class CreditCardForm extends StatefulWidget {
this.cardHolderValidator,
this.onFormComplete,
this.disableCardNumberAutoFillHints = false,
this.isCardHolderNameUpperCase = false,
super.key,
});

Expand Down Expand Up @@ -134,6 +137,9 @@ class CreditCardForm extends StatefulWidget {
/// [https://github.com/flutter/flutter/issues/104604](https://github.com/flutter/flutter/issues/104604).
final bool disableCardNumberAutoFillHints;

/// When true card holder field will make all the input value to uppercase
final bool isCardHolderNameUpperCase;

@override
State<CreditCardForm> createState() => _CreditCardFormState();
}
Expand Down Expand Up @@ -298,6 +304,14 @@ class _CreditCardFormState extends State<CreditCardForm> {
textInputAction: TextInputAction.done,
autofillHints: const <String>[AutofillHints.creditCardName],
onEditingComplete: _onHolderNameEditComplete,
textCapitalization: widget.isCardHolderNameUpperCase
? TextCapitalization.characters
: TextCapitalization.none,
inputFormatters: widget.isCardHolderNameUpperCase
? <TextInputFormatter>[
UpperCaseTextFormatter(),
]
: null,
validator: widget.cardHolderValidator,
),
),
Expand Down
5 changes: 4 additions & 1 deletion lib/src/plugin/flutter_credit_card_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ class MethodChannelFlutterCreditCard extends FlutterCreditCardPlatform {

@override
Future<void> dispose() async {
if (_isGyroscopeAvailable) {
await cancelEvents();
}
_isGyroscopeAvailable = false;
_gyroscopeEventChannel = null;
await cancelEvents();

_methodChannel = null;
}
}
12 changes: 12 additions & 0 deletions lib/src/utils/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import '../models/custom_card_type_icon.dart';
Expand Down Expand Up @@ -87,3 +88,14 @@ Widget getCardTypeImage({
},
).cardImage;
}

class UpperCaseTextFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
return TextEditingValue(
text: newValue.text.toUpperCase(),
selection: newValue.selection,
);
}
}

0 comments on commit 9dffbb7

Please sign in to comment.