---
title: Real-Time Audiences for Feature Experimentation segment qualification methods for Flutter
slug: feature-experimentation/docs/real-time-audiences-for-feature-experimentation-segment-qualification-methods-flutter
docTags: 
createdAt: 2026-08-05T20:39:53.000Z
---

## Prerequisites

You must enable and configure [Real-Time Audiences for Feature Experimentation](docId:6UBBxxRv331nBIVZ2lun8) before fetching qualified segments and checking if the user is qualified for the given audience segment.

## fetchQualifiedSegments

You can fetch user segments with the user identifier of the user context.

### Minimum SDK Version

v2.0.0 and higher

### Description

The `fetchQualifiedSegments` method retrieves the external audience mapping for a specific user from the  Optimizely Data Platform (ODP) server. The Optimizely Feature Experimentation Flutter SDK provides a synchronous and asynchronous version of the `fetchQualifiedSegments` method. The caller is blocked until the synchronous fetch is completed.

`fetchQualifiedSegments` is a method of the `UserContext` object. See [\`OptimizelyUserContext\`](docId\:qkagdzXifMComMybuU4ls) for details.

### Parameter

The following table describes the parameter for the `fetchQualifiedSegments` method:

| Parameter            | Type                          | Description                                                |
| -------------------- | ----------------------------- | ---------------------------------------------------------- |
| `options `(optional) | Set\<OptimizelySegmentOption> | A set of options for fetching qualified segments from ODP. |

### Returns

The `fetchQualifiedSegments` method returns `true` if the qualified segments array in the [user context](docId\:qkagdzXifMComMybuU4ls) was updated.

:::hint{type="info"}
**Note**
You can read and write directly to the qualified segments array. This lets you bypass the remote fetching process from ODP or use your own fetching service. This can be helpful when testing or debugging.
:::

### Example fetchQualifiedSegments

The following is an example of calling the `fetchQualifiedSegments` method and accessing the returned completion object:

```dart
Map<String, dynamic> attributes = {"app_version": "1.3.2"}; 
var user = await flutterSDK.createUserContext( 
userId: "fs-user-123", attributes: attributes); 
 
// Without segment option 
var resp = await user!.fetchQualifiedSegments(); 
if (resp.success) { 
   var decision = await user.decide("flag1"); 
   await user.trackEvent("purchase_event"); 
   } else { 
      print(resp.reason); 
} 
 
// With segment options 
Set<OptimizelySegmentOption> odpSegmentOptions = { 
   OptimizelySegmentOption.ignoreCache, 
   OptimizelySegmentOption.resetCache 
}; 

response = await user.fetchQualifiedSegments(odpSegmentOptions); 
if (response.success) { 
   var decision = await user.decide("flag1"); 
   await user.trackEvent("purchase_event"); 
   } else { 
      print(response.reason); 
} 
```

The following diagram shows the network calls between your application, the Flutter SDK, and ODP when calling `fetchQualifiedSegments`:

![](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/-Y8q7EbRGuVpaJ2qApuj1_2a68b5254211f5fe2492d5608a4924df84fcb72c9a8cd4ea6a1f8a89c55672a1-rts-network-diagrams-flutter-fetchqualifedsegments.png)

1. Your application calls the `fetchQualifiedSegments` method.
2. The Feature Experimentation Flutter SDK makes a GraphQL call to ODP to fetch audience segments the user ID qualifies for.
3. ODP responds with qualified audience segments.
4. The Flutter SDK automatically caches the fetched segments mapping the user ID to the qualified segments.
5. The `fetchQualifiedSegments` method returns a boolean if the qualified segments array was updated.
6. Call the `decide` method to get the flag decision for a given user, a decision object that contains the flag's status (enabled or disabled), and the assigned variation key.

After the segments are fetched, they are cached. This means that if you request the segments again (when new user contexts are created), you can retrieve the audience segment information from the cache instead of being fetched again from the remote ODP server.

The cache is used for the `fetchQualifiedSegments` call. This method is called on the user context (the user context is fixed, including the real-time audiences the user qualifies for).

The cache *only* applies when calling the `fetchQualifiedSegments` call. If you set the cache timeout to 0, the cache is disabled. Optimizely uses the least recently used (LRU) algorithm, so the oldest record is bumped out when the maximum size is reached. If there is a cache miss upon the method call, Optimizely makes a network request.

If you want to bypass caching, add the following options to your `odpSegmentOptions` array:

- `ignoreCache` – Bypass segments cache for lookup and save
- `resetCache` – Reset all segments cache

## isQualifiedFor

### Minimum SDK Version

v2.0.0 or higher

### Description

Check if the user is qualified for the given audience segment.

### Parameter

The following table describes the parameter for the `isQualifiedFor` method:

| Parameter | Type   | Description                                                          |
| --------- | ------ | -------------------------------------------------------------------- |
| `segment` | String | The ODP audience segment name to check if the user is qualified for. |

### Return

`true` if the user is qualified.

### Example

The following example shows whether the user is qualified for an ODP segment:

```dart
Map<String, dynamic> attributes = {"laptop_os": "mac"};
var user = await flutterSDK.createUserContext(
    userId: "user123", attributes: attributes);

var response = await user!.fetchQualifiedSegments();
if (response.success) {
  var result = await user.isQualifiedFor("segment1");
  print(result.success);
} else {
  print(response.reason);
}
```

## Source file

The language and platform source files containing the implementation for the Flutter SDK are available on [GitHub](https://github.com/optimizely/optimizely-flutter-sdk/blob/master/lib/optimizely_flutter_sdk.dart).
