Configure the Flutter SDK with an API key or JWT.

Setup & Authentication

Setup & Authentication

Add the dependency

# pubspec.yaml
dependencies:
  flasho_merchant_sdk: ^1.0.0
flutter pub get

Create a client

import 'package:flasho_merchant_sdk/flasho_merchant_sdk.dart';
 
final flasho = FlashoClient(apiKey: 'flsh_YOUR_KEY');

Create one instance and reuse it across your app — it's safe to use as a singleton.

Constructor options

ParameterTypeDescription
apiKeyString?API key starting with flsh_ — for server/website integrations
tokenString?JWT — for mobile app integrations
baseUrlString?Override the API base URL

Either apiKey or token is required. Providing neither throws an ArgumentError.


Generate a key in your Flasho dashboard under Website API.

final flasho = FlashoClient(
  apiKey: const String.fromEnvironment('FLASHO_API_KEY'),
);

💡 Keep your key secret

Never hard-code API keys in your Flutter app binary. Use environment variables or a secure backend proxy.


Option B — JWT (mobile apps)

Log in with dashboard credentials. The token is stored automatically.

final flasho = FlashoClient(token: 'placeholder');
 
final result = await flasho.auth.login(
  email: '[email protected]',
  password: 'your-password',
);
 
// Token stored — all calls now use it
print(result.merchant.sellerName);

Token expiry

JWTs expire. When you receive a FlashoApiException with isUnauthorized == true, re-login and retry:

Future<Delivery> safeCreate(CreateDeliveryRequest req) async {
  try {
    return await flasho.deliveries.create(req);
  } on FlashoApiException catch (e) {
    if (e.isUnauthorized) {
      await flasho.auth.login(email: email, password: password);
      return await flasho.deliveries.create(req);
    }
    rethrow;
  }
}

Flutter dependency injection

With provider

// main.dart
void main() {
  runApp(
    Provider<FlashoClient>(
      create: (_) => FlashoClient(apiKey: 'flsh_YOUR_KEY'),
      child: const MyApp(),
    ),
  );
}
 
// In a widget
final flasho = context.read<FlashoClient>();

With get_it

// service_locator.dart
final getIt = GetIt.instance;
 
void setupLocator() {
  getIt.registerLazySingleton<FlashoClient>(
    () => FlashoClient(apiKey: 'flsh_YOUR_KEY'),
  );
}
 
// Anywhere in your app
final flasho = getIt<FlashoClient>();

Error handling

try {
  final delivery = await flasho.deliveries.create(request);
} on FlashoApiException catch (e) {
  // API returned a non-2xx response
  debugPrint('API error ${e.statusCode}: ${e.message}');
 
  if (e.isUnauthorized)    { /* invalid API key or expired token */ }
  if (e.isValidationError) { /* bad request — check your fields */ }
  if (e.isNotFound)        { /* delivery not found */ }
 
} on FlashoNetworkException catch (e) {
  // No response — device offline or DNS failure
  debugPrint('Network error: ${e.message}');
}
ExceptionWhen thrown
FlashoApiExceptionAPI returned a non-2xx HTTP status
FlashoNetworkExceptionRequest failed before a response was received