---
updatedAt: 2026-10-02T07:52:27.000Z
agentTools:
  projectIndex: https://docs.credolab.com/llms.txt
---

# Flutter SDK Reference

# Core

## Class `CredoAppService`

Represents the bridge between Flutter and native SDK.

```
var service = CredoAppService();
```

### Method `setForceResolvePermissions()`

This method is designed to manage permission behavior on iOS.

If it is determined to be true, the SDK will automatically request permissions; otherwise, the SDK will not request permissions.

```javascript Dart
service.setForceResolvePermissions(bool force)
```

#### Parameters: 

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Description
      </th>

      <th>
        Type
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        force
      </td>

      <td>
        If `true` then SDK requests permissions automatically otherwise SDK omits requesting permissions.

        The default value is `true`.
      </td>

      <td>
        `bool`
      </td>
    </tr>
  </tbody>
</Table>

<Callout icon="📘" theme="info">
  ### Note

  Even when the value is set to false, the Music permission (`NSAppleMusicUsageDescription` in `IosMusicModule` module) will be automatically requested by the SDK when related data will be involved.
</Callout>

### Method `setIgnorePermissions()`

This method is designed to manage permission behavior on Android.

* The method sets if SDK should prevent the run of `collect()` if permissions aren't granted.
* The `true` value allows collecting dataset even if not all permissions are granted.
* The `false` value restricts collecting dataset from running until all permissions are granted (including normal permissions).
* The default value is `true`

```javascript Dart
service.setIgnorePermissions(false)
```

#### Parameters: 

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Description
      </th>

      <th>
        Type
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `ignorePermissions`
      </td>

      <td>
        The `true` value allows data collection even if not all permissions are granted. The `false` value restricts data collection until all permissions (including normal permissions) are granted.

        The default value is `true`.
      </td>

      <td>
        bool
      </td>
    </tr>
  </tbody>
</Table>

### Method `addModule()`

The method adds a module to the CredoAppService configuration.

```
await service.addModule(SampleModule());
```

#### Parameters:

| Name     | Description                | Type                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| :------- | :------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `module` | Represents platform module | `AndroidApplicationModule`<br />`AndroidCalendarModule`<br />`AndroidContactModule`<br />`AndroidAccountModule`<br />`AndroidImagesModule`<br />`AndroidIovationModule`<br />`AndroidAudioModule`<br />`AndroidVideoModule`<br />`AndroidSmsModule`<br />`AndroidTelephonyModule`<br />`IosCalendarEventsModule`<br />`IosCalendarRemindersModule`<br />`IosContactsModule`<br />`IosIovationModule`<br />`IosMusicModule`<br />`IosMediaModule` |

#### Returns:

| Type   | Description    |
| ------ | -------------- |
| Future | Returns Future |

### Method `collect()`

<Callout icon="📘" theme="info">
  Collects data from the phone and returns locally.
</Callout>

```javascript Dart
await service.collect();
```

#### Returns:

| Type                    | Description                                                                     |
| ----------------------- | ------------------------------------------------------------------------------- |
| Future\<CredoappResult> | Returns JSON dataset in compressed string format if collect action is succeeded |

## Class CredoappResult

CredoAppResult states for successful operation and contains a value

| Field Name  | Type     | Description                                                              |
| :---------- | :------- | :----------------------------------------------------------------------- |
| `value`     | `String` | Returns collected data                                                   |
| `isFailure` | `bool`   | Returns false if the operation is completed successfully otherwise true. |
| `message`   | `String` | Returns message value if the operation is failed.                        |
| `code`      | `String` | Returns [code](#error-codes) value if the operation is failed.           |

#### Error Codes

| Status Code | Reason                      | Description                          |
| ----------- | --------------------------- | ------------------------------------ |
| 30          | Duplicated areas error      | The extracting areas are duplicated. |
| 90          | Unknown error               | Unexpected error occurred.           |
| 91          | The module is not supported | Use a higher plugin version.         |

# Behavioral

## Class CredoAppBehavioral

`CredoAppBehavioral` widget is responsible for capturing a user's interaction with UI and OS for both Android and iOS platforms. The app root element has to be wrapped with `CredoAppBehavioral` widget to track all widgets that exist on the screen.

#### Constructor

| Name            | Description                                                                | Type                                                                                                     |
| :-------------- | :------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------- |
| `key`           | Construct a ValueKey\<String> with the given String                        | <Anchor target="_blank" href="https://api.flutter.dev/flutter/foundation/Key/Key.html">Key</Anchor>      |
| `startTracking` | Should the tracking process be started or not. The default value is `true` | bool                                                                                                     |
| `child`         | The widget below this widget in the tree                                   | <Anchor target="_blank" href="https://api.flutter.dev/flutter/widgets/Widget-class.html">Widget</Anchor> |

How to use CredoAppBehavioral

```typescript Dart
import 'package:flutter_behavioral/behavioral/credoapp_behavioral.dart';

void main() {
  runApp(CredoAppBehavioral(
      key: Key("root_layout"),
      startTracking: true,
      child: const MyApp()));
}

```

<Callout icon="🚧" theme="warn">
  ### Wrapping widgets with `CredoAppBehavioral` is a mandatory integration step
</Callout>

## Class BehavioralModule

`BehavioralModule` is responsible for collecting behavioral events

```javascript Dart
BehavioralModule()
```

### Static method `BehavioralModule.startTracking()`

Starts behavioral interaction metadata tracking

```javascript TypeScript
BehavioralModule.startTracking()
```

### Static method `BehavioralModule.stopTracking()`

Terminates behavioral metadata tracking

```javascript TypeScript
BehavioralModule.stopTracking()
```

### How to use start and stop tracking methods

If the `false` value has been passed for the `startTracking` parameter in `CredoAppBehavioral` widget, the tracking process must be initiated manually. To start tracking, the `BehavioralModule.startTracking()` method needs to be called. The example is below

```javascript Dart
import 'package:flutter_behavioral/module.dart'; 

ElevatedButton(onPressed: () => { BehavioralModule.startTracking()},
                    key: Key("go_to_loan_form_screen_btn"),
                    child: Text("Open Loan form screen"))
```

To stop the tracking process the `BehavioralModule.stopTracking()` method has to be called. The example is below

```javascript Dart
import 'package:flutter_behavioral/module.dart';

ElevatedButton(onPressed: () => { BehavioralModule.stopTracking()},
                    key: Key("submit_btn"),
                    child: Text("Submit"))
```

### Static method `BehavioralModule.addPlugin(dynamic plugin)`

```Text Dart
BehavioralModule.addPlugin(dynamic plugin)
```

Attaches behavioral plugin to BehavioralModule instance

### How to use addPlugin method

Make sure you add Phone Behavioral plugin after `android.permission.READ_PHONE_STATE` successful permission request or call the method on the app startup if permission is already granted.

```d Dart
if(Platform.isAndroid){
  BehavioralModule.addPlugin(AndroidPhoneBehavioralPlugin());
  BehavioralModule.addPlugin(AndroidGuardBehavioralPlugin());
}
```

## Class CredoAppNavigatorObserver

`CredoAppNavigatorObserver` connects the Behavioral module to Flutter's navigation system and provides the **Screen Name** used to associate collected behavioral events with the screen where they occur. This allows events from different screens to be distinguished and analyzed separately.

Screen context is particularly important when multiple screens contain similar UI elements or interactions. For example, taps on a **Continue** button during registration can be distinguished from taps on a **Continue** button on a payment screen.

Use it alongside `CredoAppBehavioral`: the wrapper captures user interactions with the UI, while the observer provides the navigation integration.

### create()

Obtain the SDK navigator observer using:

```dart
final observer = CredoAppNavigatorObserver.create();
```

Pass the returned observer to your navigator's observer configuration. The registration point depends on how navigation is implemented in your application.

### How to use CredoAppNavigatorObserver

For applications using `MaterialApp`, add the observer to `navigatorObservers`:

```dart
MaterialApp(
  navigatorObservers: [
    CredoAppNavigatorObserver.create(),
  ],
  home: const MyHomePage(title: 'Home Page'),
)
```

#### Other navigation configurations

| Navigation setup                                                                 | Registration point                                                                                                               |
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `MaterialApp`, `CupertinoApp`, or `WidgetsApp` using their standard constructors | Add the observer to `navigatorObservers`.                                                                                        |
| A custom `Navigator`                                                             | Add the observer to `Navigator.observers`.                                                                                       |
| Router-based navigation, such as `MaterialApp.router`                            | Register the observer through your routing package's observer configuration or the `Navigator` created by your `RouterDelegate`. |

`MaterialApp.router` does not accept `navigatorObservers`. You do not need to change your application's navigation architecture to use the observer.

### Navigation scope

Flutter delivers observer notifications for the `Navigator` to which the observer is attached. Registration on the root navigator does not automatically subscribe an observer to separate nested navigators.

Changes within an existing route, such as switching `PageView` pages without a navigation operation, are not navigator route changes.

<Callout icon="📘" theme="info">
  ### Behavioral tracking configuration

  Keep the root application widget wrapped with `CredoAppBehavioral`. Registering the navigator observer does not replace this integration step.

  Configure tracking startup through `CredoAppBehavioral.startTracking`. When set to `false`, call `BehavioralModule.startTracking()` explicitly. Use `BehavioralModule.stopTracking()` to stop tracking.
</Callout>

For the complete application setup, see [Flutter SDK Integration](https://docs.credolab.com/docs/flutter-sdk-integration). <br />

## Widget identification

<Callout icon="👍" theme="okay">
  ### Highly recommended

  **For successful integration,** we strongly recommend pass value `Key` <Anchor target="_blank" href="https://api.flutter.dev/flutter/foundation/Key/Key.html">value</Anchor> to the widget constructor, to emphasize a specific logical control or element that holds significance within the User Flow of your app.

  **For example:**

  ```jsx Dart
   ElevatedButton(onPressed: () => { },
                      key: Key("submit_btn"),
                      child: Text("Submit")),
  ```
</Callout>

<Callout icon="📘" theme="info">
  See more examples in our <Anchor target="_blank" href="https://docs.google.com/spreadsheets/d/1j4TQX0qP-X3uDdXMtIphta8GuAYg7Qb4ASEOa7lW_kY/edit#gid=0">Behavioral Module Identifiers Guide</Anchor> (Flutter)
</Callout>

<br />

<br />