Skip to main content

ar_tryon_view 0.0.8 copy "ar_tryon_view: ^0.0.8" to clipboard
ar_tryon_view: ^0.0.8 copied to clipboard

Flutter AR plugin for camera overlays and Android ARCore 3D GLB product placement, with native CameraX and AVFoundation previews.

AR Try-On View #

Flutter augmented reality (AR), virtual eyewear try-on & 3D product placement

pub.dev Pub points Pub likes Monthly downloads GitHub stars Apache 2.0 CI Android iOS

Bring interactive product previews into your Flutter application. ar_tryon_view is an open-source Flutter plugin for native camera overlays, experimental real-time 2D glasses try-on on Android, and placing GLB 3D models on real-world surfaces using Google ARCore.

Designed for developers building e-commerce, eyewear shopping, furniture visualization, product catalogs, virtual fitting experiences and augmented reality prototypes.

Pub.dev · API reference · Example app · Changelog · Report a bug

Development preview — 0.0.8: This branch introduces experimental Android face landmark tracking. The badges and pub.dev API reference reflect the published package, which may be older. Native tracking and device compatibility are not yet fully validated. Use the Git dependency below to test these new APIs before publication.


Why AR Try-On View? #

Experience What it offers
Virtual eyewear try-on Experimental eye-landmark-based 2D glasses positioning, scaling and roll on Android.
Native camera overlay Display transparent PNG graphics over a front-facing CameraX or AVFoundation preview.
3D augmented reality Select a local GLB model and place it on a horizontal surface using native Android ARCore.
Flutter-friendly integration A widget, a per-view controller and a dedicated 3D placement API.
On-device vision Face landmark inference via ML Kit; no cloud inference API key required by this plugin.
Open source Apache 2.0 license, inspectable Dart, Kotlin and Swift source.

Contents #

Features and platform support #

Capability Android iOS Web / Desktop
Native front camera preview ✅ ✅ —
Static PNG/JPG camera overlay ✅ ✅ —
Runtime image switching and clearing ✅ ✅ —
Real-time eye landmark detection 🧪 — —
Automatic 2D overlay position, scale and roll 🧪 — —
Landmark motion smoothing 🧪 — —
Hide tracked effect when eyes are lost 🧪 — —
Local GLB document picker ✅ — —
ARCore horizontal plane placement ✅ — —
Instant Placement fallback ✅ — —
Reposition 3D model ✅ — —
Unsupported-platform fallback widget ✅ ✅ ✅

✅ Implemented in source · 🧪 Experimental, device testing required · — Not implemented.

The tracking mode is 2D eyewear preview, not a calibrated physical fitting tool, full 3D facial mesh, clothing generation model or multi-face try-on engine. The static overlay remains the default on both mobile platforms.

Installation #

Published package #

flutter pub add ar_tryon_view

This installs the latest published release. Check its changelog for the APIs it contains.

Try the 0.0.8 development version #

To use the new features in this README before publication, add the Git dependency:

dependencies:
  flutter:
    sdk: flutter
  ar_tryon_view: 0.0.8
    
flutter pub get

Once version 0.0.8 is published, the equivalent dependency constraint will be ar_tryon_view: ^0.0.8.

Requirements #

Requirement Version / condition
Flutter 3.32 or newer (declared minimum)
Dart 3.8.1 or newer, below 4.0
Android API 24+ (minSdk 24)
iOS 12.0+ declared by the plugin podspec; your Flutter toolchain may require a higher minimum
Android face tracking Google Play services and available ML Kit face detection model
Android 3D AR ARCore-compatible physical device and Google Play Services for AR

See Google's ARCore supported devices list. Android platform support is not the same as hardware compatibility.

Platform setup #

Android #

Set the minimum SDK in the host app's android/app/build.gradle.kts:

android {
    defaultConfig {
        minSdk = 24
    }
}

For Groovy-based projects use minSdkVersion 24 in the same block. Add camera permission to the host app's android/app/src/main/AndroidManifest.xml, inside the manifest and outside the application element:

<uses-permission android:name="android.permission.CAMERA" />

Request camera permission at runtime before starting the preview. The examples below use the optional permission_handler package:

flutter pub add permission_handler

iOS #

Add the camera usage description to ios/Runner/Info.plist, inside its main dictionary:

<key>NSCameraUsageDescription</key>
<string>Camera access is required for the virtual try-on preview.</string>

The plugin uses AVFoundation for the static front-camera overlay and requests permission through the native camera API if needed. If using permission_handler on iOS, also follow its iOS camera configuration instructions. iOS face tracking and ARKit world placement are not yet implemented.

Quick start #

1. Add a transparent image #

Place a PNG file in your application's assets folder and register it in pubspec.yaml:

flutter:
  assets:
    - assets/glasses_01.png

2. Import and display the try-on widget #

After granting camera permission, place the widget in a bounded layout. For tracked eyewear, start the camera after the native view is laid out.

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

// Inside a widget build method, after camera permission is granted:
SizedBox(
  height: 400,
  child: ArTryOnView(
    trackFace: ArTryOnView.supportsFaceTracking,
    onCreated: (controller) {
      WidgetsBinding.instance.addPostFrameCallback((_) async {
        try {
          await controller.start();
          await controller.setEffectAsset('assets/glasses_01.png');
        } catch (error) {
          debugPrint('AR preview: $error');
        }
      });
    },
  ),
)

For a traditional static overlay, set trackFace: false or omit it entirely.

The trackFace option is read at native view creation. To change modes, recreate the platform view with a different key and manage the previous controller lifecycle.

Complete Flutter example #

A minimal interactive preview with camera permission, a tracked Android eyewear mode, a static iOS mode, and show/clear controls. Add the asset and permission configuration above first.

import 'package:ar_tryon_view/ar_tryon_view.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MaterialApp(home: TryOnPage()));
}

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

  @override
  State<TryOnPage> createState() => _TryOnPageState();
}

class _TryOnPageState extends State<TryOnPage> {
  ArTryOnController? _controller;
  bool _ready = false;

  Future<void> _start(ArTryOnController controller) async {
    try {
      if (!mounted) return;
      final permission = await Permission.camera.request();
      if (!mounted) return;

      if (!permission.isGranted) {
        _showError('Camera permission is required.');
        return;
      }

      await controller.start();
      if (!mounted) return;
      setState(() => _ready = true);
    } catch (error) {
      _showError(error);
    }
  }

  Future<void> _applyEffect() async {
    try {
      await _controller?.setEffectAsset('assets/glasses_01.png');
    } catch (error) {
      _showError(error);
    }
  }

  Future<void> _clearEffect() async {
    try {
      await _controller?.clearEffect();
    } catch (error) {
      _showError(error);
    }
  }

  void _showError(Object error) {
    if (!mounted) return;
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text(error.toString())),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Virtual Try-On')),
      body: Column(
        children: [
          Expanded(
            child: ArTryOnView(
              trackFace: ArTryOnView.supportsFaceTracking,
              unsupportedBuilder: (_) => const Center(
                child: Text('Camera preview is not supported here.'),
              ),
              onCreated: (controller) {
                _controller = controller;
                WidgetsBinding.instance.addPostFrameCallback((_) {
                  if (mounted) _start(controller);
                });
              },
            ),
          ),
          SafeArea(
            top: false,
            child: Padding(
              padding: const EdgeInsets.all(16),
              child: Row(
                children: [
                  Expanded(
                    child: FilledButton(
                      onPressed: _ready ? _applyEffect : null,
                      child: const Text('Try on glasses'),
                    ),
                  ),
                  const SizedBox(width: 12),
                  OutlinedButton(
                    onPressed: _ready ? _clearEffect : null,
                    child: const Text('Clear'),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

The platform view releases its native resources on removal. For explicit teardown while the view is still attached, use the controller's dispose() method and do not reuse that controller. For a fuller demonstration including GLB placement, see the example project.

Dynamic image overlays #

Update a product preview without rebuilding the entire camera widget:

await controller.setEffectAsset('assets/glasses_black.png');
await controller.setEffectAsset('assets/glasses_gold.png');
await controller.clearEffect();

You can also supply encoded image bytes from your own product catalog, cache or file picker:

// imageBytes is a Uint8List containing encoded PNG or JPG data.
await controller.setEffectBytes(imageBytes);

The plugin does not fetch remote assets automatically. Download or cache remote images in your application, validate them, then pass their bytes to the controller. Use transparent PNGs for overlays; JPEG has no alpha channel.

How the experimental Android tracker works #

  1. CameraX supplies preview and analysis frames.
  2. ML Kit detects facial landmarks and selects the largest detected face.
  3. Eye coordinates are mapped into preview space.
  4. Eye midpoint, distance and angle determine the 2D overlay transform.
  5. Exponential smoothing reduces visible jitter.
  6. The overlay is hidden when the required landmarks cannot be located.

Tracking is intended for a mostly front-facing user. Profile views, occlusion, low light and unsuitable asset padding can affect alignment. Actual performance has not yet been benchmarked.

3D GLB product placement #

Bring furniture, home decor, appliances or other 3D product models into a physical room using ARCore on supported Android devices.

One-line integration #

if (ArGlbPlacement.isSupported) {
  await ArGlbPlacement.pickAndOpen(modelSizeM: 0.55);
}

Pick a model, inspect its metadata and launch AR #

import 'package:ar_tryon_view/ar_tryon_view.dart';
import 'package:flutter/services.dart';

// Call from an async button handler.
try {
  if (ArGlbPlacement.isSupported) {
    final model = await ArGlbPlacement.pickGlb();

    if (model != null) {
      print('Model: ${model.name} (${model.readableSize})');
      await ArGlbPlacement.open(
        modelUri: model.uri,
        modelSizeM: 0.55,
      );
    }
  }
} on PlatformException catch (error) {
  print('AR error: ${error.code}: ${error.message}');
}

The native document picker returns null if cancelled. modelSizeM is a positive finite size parameter in meters, not a guarantee of calibrated physical dimensions.

Placement workflow #

Select local .glb model
          |
          v
    Native ARCore view
          |
          v
  Detect horizontal surface
  or use Instant Placement
          |
          v
   Aim and tap to place
          |
          v
  Anchored 3D product model

The renderer supports embedded base-color textures, baseColorFactor, multiple materials and mesh primitives, EXT_texture_webp base-color sources and common mesh index formats. Advanced PBR features (normal-map lighting, transmission, sheen, clearcoat and specular effects) are not fully implemented.

ARCore uses the rear camera and needs exclusive access. The existing CameraX preview may need to be restarted after returning from native placement. open() launches the native screen; its Future does not signal that the user has closed that screen.

API reference #

ArTryOnView #

Property / getter Type Purpose
onCreated void Function(ArTryOnController)? Obtain the controller for this platform view.
trackFace bool Opt into experimental Android 2D tracking; defaults to false.
creationParams Map<String, dynamic>? Additional parameters passed to the native view.
unsupportedBuilder WidgetBuilder? Custom fallback on unsupported platforms.
isSupported static bool Whether the current platform has a native preview implementation.
supportsFaceTracking static bool Whether the platform is Android; not a device or model readiness check.

ArTryOnController #

Method / property Purpose
id Native platform view identifier.
start() Start the front camera.
stop() Stop the camera preview.
setEffectAsset(String assetPath) Load an encoded image from Flutter assets.
setEffectBytes(Uint8List bytes) Apply encoded PNG/JPG bytes.
clearEffect() Remove the image overlay.
dispose() Explicitly release resources; controller is no longer reusable.

ArGlbPlacement and ArGlbFile #

API Purpose
ArGlbPlacement.isSupported Android platform availability check.
pickGlb() Open the native picker and return nullable model metadata.
open(modelUri: ..., modelSizeM: ...) Launch the native 3D placement screen.
pickAndOpen(modelSizeM: ...) Select and launch in one call.
ArGlbFile.uri Model document URI.
ArGlbFile.name Display filename.
ArGlbFile.sizeBytes File size, or a negative value if unknown.
ArGlbFile.readableSize Human-readable size when known.

The controller and placement methods are asynchronous. Catch PlatformException, ArgumentError and UnsupportedError as appropriate.

Architecture #

                    Flutter application
                           |
                      ar_tryon_view
                           |
           +---------------+----------------+
           |                                |
      ArTryOnView                    ArGlbPlacement
      ArTryOnController                     |
           |                           MethodChannel
     Platform view + channel                |
           |                          Android ARCore
     +-----+----------+                Native GLB renderer
     |                |
  Android            iOS
  CameraX         AVFoundation
     |
  ML Kit (optional 2D tracking)
     |
  Landmark transform + smoothing
Technology Role
Flutter / Dart Public widget, controller and placement APIs
Kotlin / CameraX Android camera preview and frame analysis
Google ML Kit On-device face landmark inference
Swift / AVFoundation iOS front camera and static image overlay
ARCore Android surface tracking and anchoring
Native GLB renderer Lightweight embedded-texture 3D visualization

Asset preparation #

Eyewear images #

  • Use transparent PNG graphics, preferably with the glasses facing forward.
  • Crop empty margins tightly and align the center between the lenses.
  • Use a consistent canvas and proportions across product variants.
  • Avoid oversized images; choose resolution appropriate for the phone preview.
  • Check the sample asset at example/assets/glasses_01.png.

GLB models #

  • Export a single binary glTF 2.0 (.glb) with embedded textures.
  • Optimize meshes and texture sizes for mobile rendering.
  • Test base-color appearance before relying on advanced PBR materials.
  • Use consistent orientation, origin and scale.
  • Test placement under real-world lighting on an ARCore-supported device.

Use cases #

Project Suitable feature
Online eyewear store Experimental Android 2D glasses preview; static overlay on iOS
Furniture shopping Android ARCore floor placement of GLB products
Retail product catalog Camera overlay and mobile 3D product visualization
Branded camera experiences Static PNG graphics and promotional overlays
AR learning and prototypes Native camera integration and surface anchoring

Jewelry, makeup and apparel fitting require additional tracking/rendering capabilities and are not advertised as implemented features.

Performance and privacy #

Performance considerations

  • CameraX analysis uses a keep-only-latest backpressure strategy to avoid building a frame queue.
  • Experimental landmark tracking uses ML Kit fast mode and a smoothed 2D transform.
  • Stop camera work when the preview is no longer needed.
  • Avoid repeatedly decoding large overlay assets; optimize 3D meshes and textures.
  • No measured FPS, latency, tracking accuracy or battery benchmarks are claimed yet.

Privacy considerations

Face landmark inference is handled by the device's ML Kit pipeline. This plugin does not implement cloud camera-frame uploads, facial identity recognition or persistent face storage. The Google Play services ML Kit model may require an initial download and is subject to Google's own data practices. The host app is responsible for permission handling, consent, privacy disclosures and any additional processing or storage.

Troubleshooting and FAQ #

Issue Suggested action
Camera permission denied Add the platform permission declarations, request permission and check device settings.
Camera view is black Check permission, view layout, lifecycle and other active camera sessions. Retry start after layout.
Tracked glasses are invisible Make both eyes visible, check Play services/model readiness and use a transparent tightly cropped PNG.
Overlay looks too large or misaligned Check padding, lens alignment, asset proportions and head pose. The experimental tracker uses a fixed eye-distance scale heuristic.
iOS does not follow the face iOS currently supports only static overlays.
AR does not launch Verify ARCore device compatibility and Google Play Services for AR installation.
GLB file is rejected Use the .glb format, a readable document URI and a valid positive model size.
Camera stops after 3D placement Restart the preview after returning to the Flutter screen.
Invalid constant value Platform capability getters are runtime values. Do not wrap widgets using those getters in const constructors.
Web or desktop shows a fallback Native camera rendering is not implemented for these platforms.
New APIs cannot be found Verify the installed package version. Use the Git development dependency for unreleased 0.0.8 APIs.

Does it require an API key or paid subscription? #

No API key or subscription is required by the current plugin. Android face detection relies on Google Play services, and ARCore requires a compatible device.

Does face tracking work offline? #

The inference is on-device once the required model is available. The Play services model may need a network connection for its initial download.

Is this a full virtual fitting or 3D face tracking SDK? #

No. Current tracked eyewear is an experimental 2D overlay. It does not provide physical measurements, face-mesh anchoring, clothing simulation or realistic occlusion.

Is GLB placement supported on iOS? #

Not yet. Current native GLB surface placement is Android-only.

Can I use this package in a commercial application? #

The project uses Apache License 2.0. Review its terms and the licenses of any dependencies or third-party product assets.

Roadmap #

The following are planned directions, not released features or guaranteed delivery dates.

Priority Planned improvement
High Validate Android tracking, improve eyewear calibration and handle camera lifecycle edge cases.
High iOS Vision face landmarks and ARKit/RealityKit product placement.
High Swift Package Manager migration and broader device testing.
Medium Face-anchored 3D models, image capture and improved rendering.
Medium Remote model loading and caching, Web camera/vision support.
Later Hand/finger tracking for rings and watches, face mesh effects and occlusion.

Follow progress or suggest a feature through GitHub Issues.

Development and contributing #

git clone https://github.com/NafimAhmed/ar-tryon-view.git
cd ar-tryon-view
git checkout improve/package-quality-and-ar-api
flutter pub get
flutter analyze
flutter test
cd example
flutter pub get
flutter run

Use a physical Android device to validate ARCore and experimental eyewear tracking. Use a physical iOS device to validate native camera overlays. CI is configured to run analysis, unit tests, a publication dry run and an Android debug build; its presence does not imply all checks have passed.

Contributions, documentation fixes, reproducible bug reports and feature requests are welcome. Include your Flutter version, platform, device model, reproduction steps and relevant error logs when reporting an issue. Avoid including private camera images or personal information in public bug reports.

License #

Released under the Apache License 2.0.

Copyright 2026 Nafim Ahmed. See LICENSE and NOTICE for details.


Made for the Flutter developer community.

If this plugin helps you build an augmented reality application, consider starring the GitHub repository or liking the package on pub.dev. Contributions and real-device feedback help improve the project.

Back to top

3
likes
0
points
299
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter AR plugin for camera overlays and Android ARCore 3D GLB product placement, with native CameraX and AVFoundation previews.

Repository (GitHub)
View/report issues

Topics

#augmented-reality #virtual-try-on #camera #arcore #e-commerce

License

unknown (license)

Dependencies

flutter

More

Packages that depend on ar_tryon_view

Packages that implement ar_tryon_view