Skip to main content
Version: Eyedid Beta

Quick Start (Flutter)

Supported Platform

  • Android
  • iOS

Supported Environment

  • Flutter >=3.3.0

  • Dart >=2.17.0 <4.0.0

  • Minimum supported Android API level is 23.

  • Target Android API level is 34.

  • Minimum supported iOS Version is 13.0.

  • Camera permission, Network permission and Network connected environment are required.

  • Build target to REAL DEVICE during the development process.

info

Eyedid SDK uses the front camera of the device

Environment Set-ups

  • Check the Development key.

  • Create the new flutter project from terminal.

    flutter create --platforms android,ios sample_app
  • Added eyedid_flutter to sample_app's pubspec.yaml file.

    dependencies:
    flutter:
    sdk: flutter
    eyedid_flutter:^1.0.0-beta3
  • Install pub packge from terminal.

    flutter pub get

Environment Set-ups (Android)

  • Add the maven repository URL 'https://seeso.jfrog.io/artifactory/visualcamp-eyedid-sdk-android-release' to the build.gradle file where eyedid is located.

    allprojects {
    repositories {
    ...
    maven {
    url "https://seeso.jfrog.io/artifactory/visualcamp-eyedid-sdk-android-release"
    }
    }
    }
  • Add the following dependencies to the app/build.gradle file.

    dependencies {
    ...
    implementation "camp.visual.eyedid.android.gazetracker:eyedid-gazetracker:{version}"
    }

Environment Set-ups (iOS)

  • Add permission to your Info.plist file.

      <key>NSCameraUsageDescription</key>
    <string></string>
  • Add PERMISSION_CAMERA=1 to your Podfile.

    target.build_configurations.each do |config|
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
    '$(inherited)',
    ...
    'PERMISSION_CAMERA=1'
    ]
    end
  • Pod install from terminal.

    pod install

Sample App Implementation

  1. Add code to check if you have camera permission.

    Future<void> checkCameraPermission() async {
    _hasCameraPermission = await _eyedidFlutterPlugin.checkCameraPermission();
    }
  2. Add a function to request camera permission.

    Future<void> checkCameraPermission() async {
    _hasCameraPermission = await _eyedidFlutterPlugin.checkCameraPermission();
    ///If you do not have camera permission, call the requesting function.
    if (!_hasCameraPermission) {
    _hasCameraPermission = await _eyedidFlutterPlugin.requestCameraPermission();
    }
    }
  3. When camera permission is obtained through the user, authentication begins by calling the initGazeTracker function.

      Future<void> initEyedid() async {
    await checkCameraPermission();
    String requestInitGazeTracker = "failed Request";
    if (_hasCameraPermission) {
    try {
    final options = GazeTrackerOptionsBuilder()
    .setPreset(CameraPreset.vga640x480)
    .setUseGazeFilter(false)
    .setUseBlink(false)
    .setUseUserStatus(false)
    .build();
    InitializedResult? initializedResult =
    await _eyedidFlutterPlugin.initGazeTracker(licenseKey: _licenseKey, options: options);
    } on PlatformException catch (e) {
    print( "Occur PlatformException (${e.message})");
    }
    }
    }
  4. When authentication is successful, eye tracking begins.

     if (initializedResult!.result) {
    try {
    _eyedidFlutterPlugin.startTracking();
    } on PlatformException catch (e) {
    print("Occur PlatformException (${e.message})");
    }
    }
  5. Set a listener to receive GazeInfo.

       _eyedidFlutterPlugin.getTrackingEvent().listen((event) {
    final info = MetricsInfo(event);
    if (info.gazeInfo.trackingState == TrackingState.success) {
    print("gaze info ${info.gazeInfo.gaze.x}, ${info.gazeInfo.gaze.y}");
    } else {
    print("gaze not found");
    }
    }
    );
  6. Here is the full code.

    import 'dart:async';
    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart';

    import 'package:eyedid_flutter/eyedid_flutter.dart';
    import 'package:eyedid_flutter/gaze_tracker_options.dart';
    import 'package:eyedid_flutter/eyedid_flutter_initialized_result.dart';
    import 'package:eyedid_flutter/events/eyedid_flutter_metrics.dart';

    class MyApp extends StatefulWidget {
    MyApp({Key? key}) : super(key: key);

    @override
    State<MyApp> createState() => _MyAppState();
    }

    class _MyAppState extends State<MyApp> {
    final _eyedidFlutterPlugin = EyedidFlutter();
    static const String _licenseKey = "Input your licenseKey"; // todo: input your license key
    double _x = 0.0, _y = 0.0;
    bool _hasCameraPermission = false;
    MaterialColor _gazeColor = Colors.red;

    @override
    void initState() {
    super.initState();
    initEyedid();
    }

    Future<void> checkCameraPermission() async {
    _hasCameraPermission = await _eyedidFlutterPlugin.checkCameraPermission();
    if (!_hasCameraPermission) {
    _hasCameraPermission = await _eyedidFlutterPlugin.requestCameraPermission();
    }
    if (!mounted) {
    return;
    }
    }

    Future<void> initEyedid() async {
    await checkCameraPermission();
    if (_hasCameraPermission) {
    try {
    final options = GazeTrackerOptionsBuilder()
    .setPreset(CameraPreset.vga640x480)
    .setUseGazeFilter(false)
    .setUseBlink(false)
    .setUseUserStatus(false)
    .build();
    InitializedResult? initializedResult =
    await _eyedidFlutterPlugin.initGazeTracker(licenseKey: _licenseKey, options: options);
    if (initializedResult!.result) {
    listenEvents();
    try {
    _eyedidFlutterPlugin.startTracking();
    } on PlatformException catch (e) {
    print("Occur PlatformException (${e.message})");
    }
    }
    } on PlatformException catch (e) {
    print("Occur PlatformException (${e.message})");
    }
    }
    }

    void listenEvents() {
    _eyedidFlutterPlugin.getTrackingEvent().listen((event) {
    MetricsInfo info = MetricsInfo(event);

    if (info.gazeInfo.trackingState == TrackingState.success) {
    setState(() {
    _x = info.gazeInfo.gaze.x;
    _y = info.gazeInfo.gaze.y;
    _gazeColor = Colors.green;
    });
    } else {
    setState(() {
    _gazeColor = Colors.red;
    });
    }
    });
    }

    @override
    Widget build(BuildContext context) {
    return MaterialApp(
    home: Scaffold(
    appBar: null, // Hide the AppBar
    body: Stack(children: <Widget>[
    Positioned(
    left: _x - 5,
    top: _y - 5,
    child: Container(
    width: 10,
    height: 10,
    decoration: BoxDecoration(
    color: _gazeColor,
    shape: BoxShape.circle,
    ),
    )),
    ])));
    }
    }