# 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 %}
