Skip to main content

Flutter Setup

In your Flutter project, ensure that your environment is properly configured as per the Flutter setup guide for your specific case.
We recommend using our demo project reference to assist you in integrating the SDK into your project

Prerequisites​

To follow along you should have basic knowledge of building apps with Flutter and Dart. In this tutorial we are going to use:

Don’t worry if you’re new to Flutter — we’ll explain everything along the way.

Run flutter doctor to verify your environment before you start.

  • Create your access key in Fynd Console → your organization → GlamAR → your product account → Settings → Tokens.
  • Any valid SKU inside your Product Inventory under GlamAR.

Visit Getting Started Page if access key or SKU has not been created

Installation​

Add the latest compatible GlamAR SDK from pub.dev:

flutter pub add glam_ar_sdk

This command updates pubspec.yaml and installs the package without requiring you to choose a version.

Now to start using the GlamAr SDK simply import it

import 'package:glam_ar_sdk/glam_ar_sdk.dart';
import 'package:glam_ar_sdk/src/core/glamar_webview_manager.dart';

Initialization​

To get started, The first step is to initialize GlamAR by calling the init function:

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:glam_ar_sdk/glam_ar_sdk.dart';
import 'package:glam_ar_sdk/src/core/glamar_webview_manager.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

await GlamAr.init(
accessKey: 'YOUR_ACCESS_KEY', // Replace with your actual key
);
}

Replace 'YOUR CONTAINER ID' with your CSS container ID and 'YOUR ACCESS KEY' with your organization AccessKey.

Basic Functions​

addEventListener​

Event listeners are essential soon after initialization is called to start listening to GlamAR SDK callback events.

GlamAr.addEventListener('loaded', (payload) {
// Triggered when the SDK has successfully loaded
// Use this to handle any setup tasks that depend on the SDK being ready
debugPrint('GlamAr SDK Initialized: \$payload');
});

GlamAr.addEventListener('sku-applied', (payload) {
debugPrint('GlamAr SDK Sku Applied: \$payload');
});

After calling init, best practise is to wait to receive the event "loaded" before calling any other function

applyBySku​

Load a virtual try-on using applyBySku method and passing the relevant SKU ID.

GlamAr.applyBySku("YOUR SKU ID"); // Replace with a valid SKU ID from your Console

applyByCategory​

Allows the client to pass a category (e.g., makeup, eyewear, jewellery), which the SDK will use to fetch all corresponding SKUs from the Console’s product inventory.

GlamAr.applyByCategory("makeup");

If storefront-specific filtering is required, pass storeFront as an optional second argument.

GlamAr.applyByCategory("makeup", {"storeFront": "store_a"});

applyBySubCategory​

Allows the client to pass a subcategory (e.g., lipstick, sunglasses, necklace), which the SDK will use to fetch all corresponding SKUs from the Console’s product inventory.

GlamAr.applyBySubCategory("lipstick");

If storefront-specific filtering is required, pass storeFront as an optional second argument.

GlamAr.applyBySubCategory("lipstick", {"storeFront": "store_a"});

open​

Use open and its mode variants only when you disable or override the SDK's built-in hero screen and implement your own screen or launch buttons. The built-in hero screen already provides buttons to open the SDK, so no open call is needed when using it. After applying a SKU, call the appropriate variant from your custom button handler.

For example, use open() to launch live try-on from your custom UI.

GlamAr.open();

Camera Permissions​

Android​

To handle camera permission handling for Android follow the given steps

  • In MainActivity.java, ensure onPermissionRequest grants camera access for WebView.
  • Add the required permissions in AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/>

iOS​

To handle camera permission handling for iOS follow the given steps

  • In Info.plist, add the following key-value pair to request camera permissions:
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera for showing ar try on's</string>
  • Inside your podfile add the following code
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
'PERMISSION_CAMERA=1', /// This is make sure we can get camera permission
]
end
end
end

Usage Example​

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:glam_ar_sdk/glam_ar_sdk.dart';
import 'package:glam_ar_sdk/src/core/glamar_webview_manager.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

await GlamAr.init(
accessKey: 'YOUR_ACCESS_KEY', // Replace with your actual key
debug: true,
);

GlamAr.addEventListener('init-complete', (payload) {
debugPrint('GlamAR SDK Initialized: \$payload');
GlamAr.applyByCategory('sunglasses');
});

GlamAr.addEventListener('loaded', (payload) {
debugPrint('GlamAR content loaded.');
});

runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});


Widget build(BuildContext context) {
return MaterialApp(
title: 'GlamAR Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const GlamArScreen(),
);
}
}

class GlamArScreen extends StatelessWidget {
const GlamArScreen({super.key});


Widget build(BuildContext context) {
return const Scaffold(
body: SafeArea(child: GlamArView()),
);
}
}

class GlamArView extends StatefulWidget {
const GlamArView({super.key});


State<GlamArView> createState() => _GlamArViewState();
}

class _GlamArViewState extends State<GlamArView> {

Widget build(BuildContext context) {
return InAppWebView(
headlessWebView: GlamArWebViewManager.getGlamArView(),
initialSettings: GlamArWebViewManager.platformSettings,
onWebViewCreated: (controller) {
GlamArWebViewManager.wireJsBridge(controller);
},
onLoadStop: (controller, url) async {
await GlamArWebViewManager.initPreview();
},
onPermissionRequest: (controller, request) async {
debugPrint('[GlamAR] onPermissionRequest');
return PermissionResponse(
action: PermissionResponseAction.GRANT,
resources: request.resources,
);
},
);
}
}