Skip to main content

Requirements

  • Dart >= 3.9.2
  • Flutter >= 3.35.7

Installation

Add the following dependency to your pubspec.yaml file:
dependencies:
  mesh_sdk_flutter: <latest_version>
You can find the latest version on pub.dev.

Localization

Mesh SDK uses the flutter_localizations package for localization. For it to work, you need to add MeshLocalizations.localizationsDelegates to your MaterialApp.localizationsDelegates:
import 'package:mesh_sdk_flutter/mesh_sdk_flutter.dart';

@override
Widget build(BuildContext context) {
  return MaterialApp(
    localizationsDelegates: [
      ...
      MeshLocalizations.localizationsDelegates,
    ],
  );
}
Link token should be obtained from the POST /api/v1/linktoken endpoint. API reference for this request is available here. The request must be performed from the server side because it requires the client’s secret. You will get the response in the following format:
{
  "content": {
    "linkToken": "{linkToken}"
  },
  "status": "ok",
  "message": ""
}
Future<void> _showMeshLinkPage(String linkToken) async {
  final result = await MeshSdk.show(
    context,
    configuration: MeshConfiguration(
      language: 'en',
      linkToken: linkToken,
      onEvent: (event) {
        print('Mesh event: $event');
      },
      onExit: (errorType) {
        print('Mesh exit: $errorType');
      },
      onIntegrationConnected: (integration) {
        print('Integration connected: $integration');
      },
      onTransferFinished: (transfer) {
        print('Transfer finished: $transfer');
      },
    ),
  );

  switch (result) {
    case MeshSuccess():
      print('Mesh link finished successfully');
    case MeshError():
      print('Mesh link error: ${result.type}');
  }
}
See full example app here.

Configuration

Here’s what you can configure in the MeshConfiguration:
ParameterTypeRequiredDescription
linkTokenStringYesLink token obtained from the backend.
languageStringNoLanguage, defaults to “en”.
isDomainWhitelistEnabledboolNoIf domain should be checked against our whitelist. Defaults to true.
integrationAccessTokensList<IntegrationAccessToken>NoList of cached IntegrationAccessTokens that you can pass, so users don’t need to connect every time.
onErrorValueChanged<MeshErrorType>?NoError callback with a MeshErrorType that describes the error.
onSuccessValueChanged<MeshSuccess>?NoSuccess callback with SuccessPayload that contains more info about the transfer or integration.
onEventValueChanged<MeshEvent>?NoCallback for when an event is triggered.
onIntegrationConnectedValueChanged<IntegrationConnectedEvent>?NoCallback for when an integration is connected. Use this to store the access token.
onTransferFinishedValueChanged<TransferFinishedEvent>?NoCallback for when a crypto transfer is executed.

Callbacks

onIntegrationConnected

Called when a user successfully connects an integration. The callback receives an IntegrationConnectedEvent containing the access token that you should securely store for future use.

onTransferFinished

Called when a crypto transfer has been executed. The callback receives a TransferFinishedEvent containing details about the transfer status and transaction information.

onEvent

Called to provide details on the user’s progress while interacting with the Link UI. This can be used for analytics and understanding user behavior.

onExit

Called when a user exits the Link flow. The callback may receive an error type if the exit was due to an error.

Using Access Tokens

If the end user has an already connected integration, you can pass the integrationAccessTokens to skip re-authentication:
final result = await MeshSdk.show(
  context,
  configuration: MeshConfiguration(
    linkToken: linkToken,
    integrationAccessTokens: const [
      IntegrationAccessToken(
        accessToken: 'token',
        accountId: 'id',
        accountName: 'name',
        brokerName: 'broker',
        brokerType: 'type',
      ),
    ],
    onTransferFinished: (transfer) {
      print('Transfer finished: $transfer');
    },
  ),
);

Whitelist

By default, domain whitelisting is enabled. To disable the whitelist check, set isDomainWhitelistEnabled: false in the MeshConfiguration.