DigitalWalletButton class

A button for initiating digital wallet payments.

On Android, it will display a native Google Pay button and on iOS it will display a native Apple Pay button.

Use the onClicked event handler to call OloPaySdk.createDigitalWalletPaymentMethod and launch the digital wallet payment sheet flow.

Sizing Considerations:

This widget hosts native Android and iOS buttons. The native views are wrapped by a ConstrainedBox with default constraints set to BoxConstraints(maxHeight: 45). This can be customized using the constraints property.

If the height of the Flutter container exceeds the height of the native button, the native button will be centered vertically in the Flutter container.

Example Implementation

Future<void> onDigitalWalletButtonClicked() async {
  DigitalWalletPaymentParameters paymentParams = DigitalWalletPaymentParameters(
    amount: 1.23,
  );

  try {
    // Present the Apple Pay or Google Pay payment sheet and generate a
    // payment method
    PaymentMethod? paymentMethod =
      await _oloPaySdkPlugin?.createDigitalWalletPaymentMethod(paymentParams);

    if (paymentMethod == null) {
      // Handle user canceled state
    } else {
      // 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) {
  if (_digitalWalletsReady)
    DigitalWalletButton(
      onClicked: onDigitalWalletButtonClicked,
    ),
}
Inheritance

Constructors

DigitalWalletButton({Key? key, OnDigitalWalletButtonClicked? onClicked, ApplePayButtonConfiguration applePay = const ApplePayButtonConfiguration.only(), BoxConstraints constraints = const BoxConstraints(maxHeight: 45), bool enabled = true, GooglePayButtonConfiguration googlePay = const GooglePayButtonConfiguration.only()})
Creates a new instance of this widget
const

Properties

applePay ApplePayButtonConfiguration
Configuration parameters for displaying an Apple Pay Button
final
constraints BoxConstraints
Property to set the native view's height and width. Default is BoxConstraints(maxHeight: 45)
final
enabled bool
Whether or not the button should be enabled and allow click events
final
googlePay GooglePayButtonConfiguration
Configuration parameters for displaying a Google Pay button
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onClicked OnDigitalWalletButtonClicked?
A callback function to be executed when the digital wallet button is clicked
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<StatefulWidget>
Creates the mutable state for this widget at a given location in the tree.
override
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