CardDetailsSingleLineTextField class

Widget responsible for displaying a credit card input field

This widget displays all credit card input details in a single input field

Important: Card details are intentionally restricted for PCI compliance

Sizing Considerations:

This widget hosts native Android and iOS views and an error label contained within a Column. The native view is wrapped by a ConstrainedBox with default constraints set to BoxConstraints(maxHeight: 45). This can be customized using the constraints property.

Sizing Behavior Prior to v1.2.0

Prior to v1.2.0 Android and iOS had different widget sizing behavior. The iOS native view would properly resize to fit the size specified by its Flutter container widget.

The Android native view, however, would only take up as much space as it needed, according to its intrinsic content size. If the size specified for its Flutter container widget's height was larger than the space it required, this would lead to extra empty space below the Android native view.

This has been fixed in v1.2.0, and the Android native view now properly resizes to fit the size specified by its Flutter container widget.

Example Implementation

CardDetailsSingleLineTextFieldController? _cardInputController;

void onSingleLineControllerCreated(CardDetailsSingleLineTextFieldController controller) {
  _cardInputController = controller;
}

Future<void> createPaymentMethod() async {
  try {
    var paymentMethod = await _cardInputController?.createPaymentMethod();
    if (paymentMethod != null) {
      // Use paymentMethod to submit an order to Olo's Ordering API:
      // https://developer.olo.com/docs/load/olopay#section/Submitting-a-Basket-via-the-Ordering-API
    }
  } on PlatformException catch (e) {
    // Handle errors
  }
}

@override
Widget build(BuildContext context) {
  return Center(
    child: Column(
      children: <Widget>[
        CardDetailsSingleLineTextField(
          onControllerCreated: onSingleLineControllerCreated,
        ),
        ElevatedButton(
          onPressed: createPaymentMethod,
          child: const Text("Submit Card Details"),
        ),
      ],
    ),
  ),
}
Inheritance

Constructors

CardDetailsSingleLineTextField({Key? key, required CardDetailsSingleLineTextFieldControllerCreated onControllerCreated, BackgroundStyles? backgroundStyles, CustomErrorMessages? customErrorMessages, TextStyle? errorStyles, CardDetailsErrorMessageChanged? onErrorMessageChanged, CardDetailsFocusChanged? onFocusChanged, CardDetailsInputChanged? onInputChanged, CardDetailsValidStateChanged? onValidStateChanged, TextStyles? textStyles, BoxConstraints constraints = const BoxConstraints(maxHeight: 45), bool displayErrorMessages = true, bool enabled = true, Alignment errorAlignment = Alignment.center, double errorMarginTop = _defaultErrorMarginTop, Hints hints = Hints.singleLineDefaults, PaddingStyles paddingStyles = PaddingStyles.defaults})
Creates a new instance of this widget
const

Properties

backgroundStyles → BackgroundStyles?
Provide custom background styles for this widget
final
constraints → BoxConstraints
Property to set the native view's height and width. Default is BoxConstraints(maxHeight: 45)
final
customErrorMessages → CustomErrorMessages?
Provide custom error messages
final
displayErrorMessages → bool
Determines if error messages are displayed. Default is true
final
enabled → bool
Whether or not this widget will respond to user interactions
final
errorAlignment → Alignment
Alignment of the built-in error message. Default is center
final
errorMarginTop → double
Set the margin between the input widget and the error message. Default is 8.0
final
errorStyles → TextStyle?
Customize the look and feel of the built-in error message
final
hashCode → int
The hash code for this object.
no setterinherited
hints → Hints
Provide custom hint text for fields of this widget
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onControllerCreated → CardDetailsSingleLineTextFieldControllerCreated
A callback function to be notified when the controller associated with this widget is ready
final
onErrorMessageChanged → CardDetailsErrorMessageChanged?
A callback function to be notified when the error message associated with this widget changes
final
onFocusChanged → CardDetailsFocusChanged?
A callback function to be notified when the focused state of this widget changes
final
onInputChanged → CardDetailsInputChanged?
A callback function to be notified when user-entered input changes
final
onValidStateChanged → CardDetailsInputChanged?
A callback function to be notified when the valid state of this widget changes
final
paddingStyles → PaddingStyles
Provide custom padding for this widget (Android Only)
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
textStyles → TextStyles?
Provide custom text styles for this widget
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited