diff --git a/CHANGELOG.md b/CHANGELOG.md index 4acbf16..824ba4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index ca3b237..9494a20 100644 --- a/README.md +++ b/README.md @@ -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 }, diff --git a/lib/src/credit_card_form.dart b/lib/src/credit_card_form.dart index e8b0a36..186640e 100644 --- a/lib/src/credit_card_form.dart +++ b/lib/src/credit_card_form.dart @@ -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'; @@ -35,6 +37,7 @@ class CreditCardForm extends StatefulWidget { this.cardHolderValidator, this.onFormComplete, this.disableCardNumberAutoFillHints = false, + this.isCardHolderNameUpperCase = false, super.key, }); @@ -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 createState() => _CreditCardFormState(); } @@ -298,6 +304,14 @@ class _CreditCardFormState extends State { textInputAction: TextInputAction.done, autofillHints: const [AutofillHints.creditCardName], onEditingComplete: _onHolderNameEditComplete, + textCapitalization: widget.isCardHolderNameUpperCase + ? TextCapitalization.characters + : TextCapitalization.none, + inputFormatters: widget.isCardHolderNameUpperCase + ? [ + UpperCaseTextFormatter(), + ] + : null, validator: widget.cardHolderValidator, ), ), diff --git a/lib/src/plugin/flutter_credit_card_method_channel.dart b/lib/src/plugin/flutter_credit_card_method_channel.dart index a749cf1..a7c437a 100644 --- a/lib/src/plugin/flutter_credit_card_method_channel.dart +++ b/lib/src/plugin/flutter_credit_card_method_channel.dart @@ -77,9 +77,12 @@ class MethodChannelFlutterCreditCard extends FlutterCreditCardPlatform { @override Future dispose() async { + if (_isGyroscopeAvailable) { + await cancelEvents(); + } _isGyroscopeAvailable = false; _gyroscopeEventChannel = null; - await cancelEvents(); + _methodChannel = null; } } diff --git a/lib/src/utils/helpers.dart b/lib/src/utils/helpers.dart index 6e17380..d393226 100644 --- a/lib/src/utils/helpers.dart +++ b/lib/src/utils/helpers.dart @@ -1,3 +1,4 @@ +import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import '../models/custom_card_type_icon.dart'; @@ -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, + ); + } +}