# Feature Flags in Flutter

### Installation

```sh
$ flutter pub add feature_flags_toggly
```

This will add a line like this to your package's `pubspec.yaml` (and run `flutter pub get`):

```dart
dependencies:
  feature_flags_toggly: ^0.0.1
```

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Now in your Dart code, you can use:

```dart
import 'package:feature_flags_toggly/feature_flags_toggly.dart';
```

### Basic Usage <a href="#basic-usage-with-togglyio" id="basic-usage-with-togglyio"></a>

Initialize Toggly by running the `Toggly.init` method and by providing your `App Key` from your [Toggly application page](https://app.toggly.io)

```dart
@override
void initState() {
  initToggly();
  super.initState();
}

void initToggly() async {
  await Toggly.init(
    appKey: '<YOUR_APP_KEY>',
    environment: '<YOUR_APP_ENVIRONMENT>',
  );
}
```

Now simply wrap your widgets in `Feature` widgets and provide them with the `featureKeys` that best describe them.

```dart
Feature(
  featureKeys: const ['ExampleFeatureKey1'],
  child: const Text('This text will show if ExampleFeatureKey1 is FALSE'),
),
```

You can also use multiple feature keys for one Feature widget and make use of the *requirement* (`FeatureRequirement.all`, `FeatureRequirement.any`) and `negate` (bool) options.

{% content-ref url="feature-flags-in-flutter/feature-widget" %}
[feature-widget](https://docs.toggly.io/feature-flags/feature-flags-in-flutter/feature-widget)
{% endcontent-ref %}

{% content-ref url="feature-flags-in-flutter/directly-checking-a-flag" %}
[directly-checking-a-flag](https://docs.toggly.io/feature-flags/feature-flags-in-flutter/directly-checking-a-flag)
{% endcontent-ref %}


---

# 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://docs.toggly.io/feature-flags/feature-flags-in-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.
