Skip to content

Conversation

RahmiTufanoglu
Copy link
Contributor

The AdyenCardComponent has been refactored from a StatelessWidget to a StatefulWidget. This change allows for better state management, particularly for the asynchronous fetching of the SDK version number.

The build logic has been streamlined by:

  • Moving the SDK version number fetching to initState.
  • Introducing dedicated internal widgets (_CardSessionFlowWidget and _CardAdvancedFlowWidget) to handle the different checkout flows (Session and Advanced). This separation improves code organization and makes the main build method cleaner.
  • The _determineInitialHeight method and its platform-specific helpers remain, but their usage is now within the context of the new stateful widget structure.

These changes enhance the component's maintainability and readability without altering its core functionality.

Summary

Tested scenarios

Fixed issue:

The AdyenCardComponent has been refactored from a StatelessWidget to a StatefulWidget. This change allows for better state management, particularly for the asynchronous fetching of the SDK version number.

The build logic has been streamlined by:
- Moving the SDK version number fetching to `initState`.
- Introducing dedicated internal widgets (`_CardSessionFlowWidget` and `_CardAdvancedFlowWidget`) to handle the different checkout flows (Session and Advanced). This separation improves code organization and makes the main build method cleaner.
- The `_determineInitialHeight` method and its platform-specific helpers remain, but their usage is now within the context of the new stateful widget structure.

These changes enhance the component's maintainability and readability without altering its core functionality.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @RahmiTufanoglu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the AdyenCardComponent from a StatelessWidget to a StatefulWidget to improve state management, particularly for asynchronously fetching the SDK version number. The changes also streamline the component's build logic by moving data fetching to initState and introducing dedicated internal widgets to handle different checkout flows, enhancing overall code organization, readability, and maintainability without altering core functionality.

Highlights

  • Widget Type Conversion: The AdyenCardComponent has been converted from a StatelessWidget to a StatefulWidget to enable proper state management, specifically for handling asynchronous operations like fetching the SDK version.
  • State Management Improvement: The asynchronous fetching of the SDK version number has been moved from the build method to the initState method of the new _AdyenCardComponentState, ensuring the data is fetched once when the widget is initialized.
  • Code Organization: Two new private StatelessWidgets, _CardSessionFlowWidget and _CardAdvancedFlowWidget, have been introduced to encapsulate the rendering logic for the distinct Session and Advanced checkout flows, significantly cleaning up the main build method of AdyenCardComponent.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors AdyenCardComponent from a StatelessWidget to a StatefulWidget, which improves state management. The introduction of dedicated widgets for different checkout flows enhances code organization. The review focuses on refining the build method to enhance type safety, consistency, and performance by centralizing calculations and ensuring parameters are handled uniformly across the new widgets.

Comment on lines 53 to 74
return switch (widget.checkout) {
SessionCheckout() => _CardSessionFlowWidget(
configuration: widget.configuration,
paymentMethod: widget.paymentMethod,
checkout: widget.checkout,
onPaymentResult: widget.onPaymentResult,
sdkVersionNumber: sdkVersionNumber,
initialHeight: _determineInitialHeight(widget.configuration.cardConfiguration),
isStoredPaymentMethod: widget.paymentMethod.containsKey(_isStoredPaymentMethodIndicator),
),
AdvancedCheckout it => _CardAdvancedFlowWidget(
configuration: widget.configuration,
paymentMethod: widget.paymentMethod,
advancedCheckout: it,
onPaymentResult: widget.onPaymentResult,
sdkVersionNumber: sdkVersionNumber,
encodedPaymentMethod: json.encode(widget.paymentMethod),
gestureRecognizers: widget.gestureRecognizers,
initialHeight: _determineInitialHeight(widget.configuration.cardConfiguration),
isStoredPaymentMethod: widget.paymentMethod.containsKey(_isStoredPaymentMethodIndicator),
),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve type safety and reduce redundancy, consider capturing the SessionCheckout instance in the switch statement, similar to how it's done for AdvancedCheckout. This allows passing the correctly typed object to _CardSessionFlowWidget, avoiding the need for casting within that widget. Additionally, pre-calculate initialHeight, isStoredPaymentMethod, and encodedPaymentMethod outside the switch to avoid redundant calculations. Finally, the paymentMethod map is passed to _CardAdvancedFlowWidget but is not used. After refactoring, it will also become unused in _CardSessionFlowWidget.

        if (snapshot.hasData) {
          final sdkVersionNumber = snapshot.data!;
          final initialHeight = _determineInitialHeight(widget.configuration.cardConfiguration);
          final isStoredPaymentMethod = widget.paymentMethod.containsKey(_isStoredPaymentMethodIndicator);
          final encodedPaymentMethod = json.encode(widget.paymentMethod);

          return switch (widget.checkout) {
            SessionCheckout session => _CardSessionFlowWidget(
                configuration: widget.configuration,
                sessionCheckout: session,
                onPaymentResult: widget.onPaymentResult,
                sdkVersionNumber: sdkVersionNumber,
                initialHeight: initialHeight,
                isStoredPaymentMethod: isStoredPaymentMethod,
                encodedPaymentMethod: encodedPaymentMethod,
              ),
            AdvancedCheckout it => _CardAdvancedFlowWidget(
                configuration: widget.configuration,
                advancedCheckout: it,
                onPaymentResult: widget.onPaymentResult,
                sdkVersionNumber: sdkVersionNumber,
                encodedPaymentMethod: encodedPaymentMethod,
                gestureRecognizers: widget.gestureRecognizers,
                initialHeight: initialHeight,
                isStoredPaymentMethod: isStoredPaymentMethod,
              ),
          };
        }

…owWidget

The `AdyenCardComponent` now directly returns either `CardSessionComponent` or `CardAdvancedComponent` based on the checkout type, simplifying the widget tree.
The `super.initState()` call was moved before widget-specific initialization in `BaseCardComponent` to ensure the base class is properly initialized first.
The loading widget for the CardComponent has been refactored for better readability and conciseness.
The separate `_buildLoadingWidget` method has been removed, and its logic is now inline using a switch expression.
This change maintains the existing behavior of showing a `CircularProgressIndicator` on Android and an empty `SizedBox` on other platforms.
@Robert-SD Robert-SD self-assigned this Jul 29, 2025
@Robert-SD
Copy link
Collaborator

Duplicated of #491

@Robert-SD Robert-SD closed this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants