ansa_flutter_sdk 0.0.2 copy "ansa_flutter_sdk: ^0.0.2" to clipboard
ansa_flutter_sdk: ^0.0.2 copied to clipboard

Ansa Flutter SDK - A Flutter SDK for integrating Ansa Core and Ansa UI functionalities into your Flutter applications.

Ansa Flutter SDK #

Ansa Flutter SDK - A Flutter SDK for integrating Ansa Core and Ansa UI functionalities into your Flutter applications.

Overview #

This package wraps two core functionalities:

  • Ansa Core: A headless core SDK that allows you to manage your UI while leveraging Ansa's powerful backend.
  • Ansa UI: Pre-built UI components that use Ansa Core under the hood.

The Ansa Flutter SDK is compatible with both Android and iOS platforms. This guide will help you integrate the SDK into your Flutter application using best practices.


Installation #

Add the Ansa Flutter SDK to your pubspec.yaml:

dependencies:
  ansa_flutter_sdk: ^0.0.1

Then, run the following command:

flutter pub get

Setup #

To integrate the SDK into your Flutter application:

1. Enable Swift Package Manager #

Flutter's Swift Package Manager (SPM) support is disabled by default. To enable it, follow these steps:

  1. Switch to Flutter's main channel:

    flutter channel main --no-cache-artifacts
    
  2. Upgrade to the latest Flutter SDK:

    flutter upgrade
    
  3. Enable the Swift Package Manager feature:

    flutter config --enable-swift-package-manager
    

Once enabled, running your Flutter app will automatically migrate the iOS project to support SPM integration. For more details, refer to Flutter's Swift Package Manager Documentation.


2. Initialize the SDK #

You’ll need your Merchant Publishable Key from the Ansa Portal. For details on obtaining API keys and setting up customers, refer to the Ansa Documentation.

Use the following code to initialize the SDK in your main.dart:

import 'package:ansa_flutter_sdk/ansa_flutter_sdk.dart';
import 'package:ansa_flutter_sdk/ansa_logger.dart';

final _ansaFlutterSdk = AnsaFlutterSdk();

Future<void> initializeAnsaSdk() async {
  await _ansaFlutterSdk.initializeSdk(
    publishableKey: 'your-publishable-key',
    logLevel: LogLevel.info,
  );

  _ansaFlutterSdk.setupClientSecretProvider((String customerId) async {
    // Fetch the client secret from your backend securely
    return 'your-client-secret-key';
  });
}

Important: Securely fetch the client secret key from your backend server in production.

3. Add Pre-Built UI Components #

You can integrate pre-built UI components like the ManagedAnsaBalanceScreen for balance management:

import 'package:ansa_flutter_sdk/ansa_flutter_sdk.dart';
import 'package:flutter/material.dart';

class BalanceScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ManagedAnsaBalanceScreen(
      customerId: 'your-customer-id',
      merchantId: 'your-merchant-id',
    );
  }
}

Features #

Core API Methods #

  • Customer Management: Fetch and manage customer data.
  • Merchant Management: Retrieve merchant details.
  • Payment Methods: Add, fetch, and delete payment methods.
  • Balance Management: Add and use balances programmatically.
  • Auto Reload: Configure and manage auto-reload settings.
  • Transactions: Fetch transaction details.

Pre-Built UI Components #

  • ManagedAnsaBalanceScreen: Displays the balance widget, allowing users to view and manage their balance.

Example Usage #

Here’s a simple example app integrating various features of the SDK:

import 'package:ansa_flutter_sdk/ansa_flutter_sdk.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  final _ansaFlutterSdk = AnsaFlutterSdk();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Ansa Flutter SDK Example')),
        body: Column(
          children: [
            ElevatedButton(
              onPressed: () async {
                await _ansaFlutterSdk.initializeSdk(
                  publishableKey: 'your-publishable-key',
                  logLevel: LogLevel.info,
                );
              },
              child: const Text('Initialize SDK'),
            ),
            ElevatedButton(
              onPressed: () async {
                final customer = await _ansaFlutterSdk.customer
                    .getCustomer(customerId: 'your-customer-id');
                print(customer);
              },
              child: const Text('Fetch Customer'),
            ),
          ],
        ),
      ),
    );
  }
}

Logging #

You can configure logging during SDK initialization:

_ansaFlutterSdk.initializeSdk(
  publishableKey: 'your-publishable-key',
  logLevel: LogLevel.debug,
);

Supported Platforms #

  • iOS: Requires iOS 16.0+
  • Android: Requires Android API Level 26+

Resources #

For any questions, feel free to reach out to your implementation manager or open an issue on GitHub.

1
likes
0
points
19
downloads

Publisher

verified publisheransa.dev

Weekly Downloads

Ansa Flutter SDK - A Flutter SDK for integrating Ansa Core and Ansa UI functionalities into your Flutter applications.

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ansa_flutter_sdk

Packages that implement ansa_flutter_sdk