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 authored and vatsaltanna-simformsolutions committed Jan 10, 2025
1 parent d8e2c0d commit dd7ac38
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- 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).
- Fixed Gradle issues [#181](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/181).
- Added `isCardHolderNameUpperCase` to make card holder text field always accept uppercase [#174](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/174).
- Added support for 'mir' cards [#159](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/159).

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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
expiryDateValidator: (String? expiryDate){},
cvvValidator: (String? cvv){},
cardHolderValidator: (String? cardHolderName){},
isCardHolderNameUpperCase: true,
onFormComplete: () {
// callback to execute at the end of filling card data
},
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 dd7ac38

Please sign in to comment.