GooglePayButton class

Shows the Google Pay payment sheet to the user.

This line triggers the pay plugin to display the Google Pay payment UI, using the configuration and payment items provided.

Internally, it calls the showPaymentSelector() method from the Pay class, which:

  • Opens the Google Pay interface (on iOS)
  • Uses the payment details defined in paymentItems
  • Returns the result of the transaction (such as success, failure, or cancellation)

Parameters:

  • PayProvider.flutter_pay_buttons: Tells the plugin to use Google Pay as the payment method.
  • widget.paymentItems: A list of items showing what the user is paying for (e.g., product names, totals).

Example of what's happening:

final result = await _pay.showPaymentSelector(
  PayProvider.flutter_pay_buttons,
  [
    PaymentItem(label: 'Total', amount: '49.99'),
  ],
);

Result:

The result is a Map<String, dynamic> containing information about the outcome of the payment. It's passed to the onPaymentResult() callback:

widget.onPaymentResult(result);

A custom Google Pay button widget that integrates with the pay plugin. It allows easy setup of Google Pay payment flow with UI customization options.

Inheritance

Constructors

GooglePayButton({Key? key, double? height, double? width, EdgeInsets? margin, Color? backgroundColor, double? cornersRadius, bool isTesting = false, CheckoutOption checkoutOption = CheckoutOption.lazy, int? apiVersion, int? apiVersionMinor, List<String>? allowedCardNetworks, bool billingAddressRequired = false, String? billingAddressFormat, bool phoneNumberRequired = false, TokenizationSpecificationType tokenizationSpecificationType = TokenizationSpecificationType.direct, Map<String, dynamic>? tokenizationSpecificationParameters, String? publicKey, String? currencyCode, TransactionInfoStatus? transactionInfoStatus, Widget? child, MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start, MainAxisSize mainAxisSize = MainAxisSize.min, required FutureOr<void> onPaymentResult(Map<String, dynamic> result), required List<PaymentItem> paymentItems, required String totalPrice, required String merchantId, required String merchantName})
const

Properties

allowedCardNetworks → List<String>?
Allowed card networks (e.g., VISA, MASTERCARD).
final
apiVersion → int?
API version for Google Pay.
final
apiVersionMinor → int?
Minor version of the API.
final
backgroundColor → Color?
Background color of the button.
final
billingAddressFormat → String?
Billing address format (e.g., "FULL" or "MINIMAL").
final
billingAddressRequired → bool
Whether billing address is required in the payment.
final
checkoutOption → CheckoutOption
Checkout option type (immediate or lazy).
final
child → Widget?
Optional custom child widget to replace the default design.
final
cornersRadius → double?
Border radius for rounded corners.
final
currencyCode → String?
Currency code (e.g., USD, EUR).
final
hashCode → int
The hash code for this object.
no setterinherited
height → double?
Height of the Google Pay button.
final
isTesting → bool
Whether to use the Google Pay test environment.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
mainAxisAlignment → MainAxisAlignment
Main axis alignment for button content.
final
mainAxisSize → MainAxisSize
Main axis size for button layout.
final
margin → EdgeInsets?
External margin around the button.
final
merchantId → String
Merchant ID for Google Pay.
final
merchantName → String
Merchant name displayed in Google Pay.
final
onPaymentResult → FutureOr<void> Function(Map<String, dynamic> result)
Callback invoked when a payment result is received.
final
paymentItems → List<PaymentItem>
List of payment items to be shown in the payment sheet.
final
phoneNumberRequired → bool
Whether phone number is required for billing address.
final
publicKey → String?
Public key used for direct tokenization.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
tokenizationSpecificationParameters → Map<String, dynamic>?
Parameters for tokenization (required for payment gateway type).
final
tokenizationSpecificationType → TokenizationSpecificationType
Type of tokenization (e.g., direct or payment gateway).
final
totalPrice → String
Total transaction price as a string.
final
transactionInfoStatus → TransactionInfoStatus?
Status of transaction info (e.g., final or estimated).
final
width → double?
Width of the Google Pay button.
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<GooglePayButton>
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