# Flutter

{% hint style="info" %}
Latest Version: [1.2.2](https://pub.dev/packages/surveysparrow_flutter_sdk)
{% endhint %}

Below are the various processes involved in setting up Spotcheck in Flutter. Kindly refer example applications [here](https://github.com/surveysparrow/surveysparrow-flutter-sdk/tree/master/example)

### Installation

To install the SurveySparrowSdk, make sure you are in the root folder of your Flutter project in the terminal and run the following command.

```bash
flutter pub add surveysparrow_flutter_sdk
```

***

Additionally to use the **camera accessibility**, add the following permissions to the app.

#### Android:

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

#### IOS:

```swift
<key>NSCameraUsageDescription</key>
<string>REASON</string> 
```

***

Also for **voice transcription** support, add the following permissions to the app.

#### Android:

```xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
```

#### IOS:

```swift
<key>NSMicrophoneUsageDescription</key>
<string>REASON</string>
        
<key>NSSpeechRecognitionUsageDescription</key>
<string>REASON</string>
```

***

### Initialization

Declare and initialize the spotcheck variable using the Spotcheck().

**Anonymous users**

If you wish not to keep track of users' data, you can follow the below syntax for initialization.

```dart
final SpotCheck spotCheck = SpotCheck(
  domainName: "<your_domain>",
  targetToken: "<target_token>",
  // Should Not Pass userDetails as const
  userDetails: {},
  variables: {},
  customProperties: {},
  sparrowLang: "ta" // Eg: ta, en, 
);
```

**Known Users**

If you wish to keep track of users' data and perform conditional Survey triggers, you can follow the below syntax for initialization.

<pre class="language-dart"><code class="lang-dart"><strong>final SpotCheck spotCheck = SpotCheck(
</strong>  domainName: "&#x3C;your_domain>",
  targetToken: "&#x3C;target_token>",
  // Should Not Pass userDetails as const
  userDetails: {
       email:"&#x3C;user_email>",
       mobile:"&#x3C;user_mobile>",
       uuid: '&#x3C;uuid_value>' // Optional
  },
  variables: {
        sparrowLang: "ta" // Eg: ta, en, 
       &#x3C;api_identifier_of_variable>:"&#x3C;variable_value>",
  },
  customProperties: {
       &#x3C;custom_property_name>: "&#x3C;custom_property_value>"
  }
);
</code></pre>

Then, add the SpotCheck initialized variable to your app screen. Add it only once in the builder of your Material App.

```dart
MaterialApp(
  <Your-Code>
  builder: (context, child) {
    return Stack(
      children: [
        child ?? const SizedBox(),
        spotCheck,
      ],
    );
  }
  <Your-Code>
  )
```

### Screen Track

It provides the ability to keep track of screens the users are visiting and to enable the survey trigger on that screen.

#### Syntax:

```swift
spotCheck.trackScreen("ScreenName");
```

#### Example:

If a survey needs to be triggered on the payment page, the name of the ScreenName should be specified in the TrackScreen function.

```kotlin
spotCheck.trackScreen("paymentScreen");
```

### Event Track

It provides the ability to keep track of events which when triggered, will enable the survey to be popped.&#x20;

#### Syntax:

```swift
spotCheck.trackEvent("ScreenName", {"EventName": {}});
```

#### Example:

If a survey needs to be triggered when the user completes a payment, then the TrackEvent function should be called with the respective ScreenName and optional custom properties.

```swift
spotCheck.trackEvent("paymentScreen", {"paymentComplete": {
    "email":"naveen@surveysparrow.com",
    "paymentStatus":true
}});
```

{% hint style="info" %}
Make sure to have the eventName configured in the Checks section of the configure panel
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://surveysparrow.gitbook.io/spotchecks/how-to-use-spotchecks/mobile-spotchecks/flutter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
