# Install and Set Up the Flutter Plugin

Learn how to install the Airship Flutter plugin, configure iOS and Android platforms, and initialize the SDK.

This guide walks you through installing the Airship Flutter plugin and configuring it for both iOS and Android platforms.

## Requirements

- Flutter 3.0.2 or higher
- iOS 15+ (Xcode 16+)
- Android API 23+

## Install the plugin

1. Add the Airship dependency to your package's `pubspec.yaml` file:

   
```yaml
dependencies:
      airship_flutter: ^flutterPluginVersion
```


2. Install your Flutter package dependencies by running the following in the command line at your project's root directory:

   `flutter pub get`

3. Import Airship into your Dart code:

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



## Initialize Airship

The Airship SDK requires a single entry point called `takeOff` to initialize. Call `takeOff` in your app's `main()` function before running the app. This ensures Airship is ready before any widgets are built.

### Get your app credentials

Before calling `takeOff`, you'll need your app credentials from the Airship dashboard:

1. Log in to the [Airship dashboard](https://go.airship.com/) and open your project.
1. Select the dropdown menu () next to your project name, and then **Project details**.
1. Copy your **App Key** and **App Secret**.

> **Important:** Airship provides separate credentials for development and production environments. The SDK automatically selects the correct credentials based on your build configuration. However, Flutter doesn't have a built-in way to detect this, so you can use the `inProduction` flag or configure based on build mode.


### Configure takeOff

The following example shows how to configure and call `takeOff` in your Flutter app:

```dart
import 'package:flutter/material.dart';
import 'package:airship_flutter/airship_flutter.dart';

void main() {
  // Ensure Flutter is initialized
  WidgetsFlutterBinding.ensureInitialized();

  // Configure Airship
  var config = AirshipConfig(
    // Development environment credentials
    defaultEnvironment: ConfigEnvironment(
      appKey: "YOUR_DEVELOPMENT_APP_KEY",
      appSecret: "YOUR_DEVELOPMENT_APP_SECRET"
    ),
    
    // Production environment credentials (optional but recommended)
    productionEnvironment: ConfigEnvironment(
      appKey: "YOUR_PRODUCTION_APP_KEY",
      appSecret: "YOUR_PRODUCTION_APP_SECRET"
    ),
    
    // Set to true for production builds
    inProduction: false, // Set to true for production or use const bool.fromEnvironment('dart.vm.product')
    
    // Cloud site: Site.us for US, Site.eu for EU
    site: Site.us
  );

  // Initialize Airship
  Airship.takeOff(config);

  // Run your app
  runApp(MyApp());
}
```


### Configuration options

Key configuration options include:

* **defaultEnvironment**: Credentials for your development/staging environment
* **productionEnvironment**: Credentials for your production environment (optional but recommended)
* **inProduction**: Set to `true` for production builds, `false` for development. You can use `const bool.fromEnvironment('dart.vm.product')` to automatically detect release builds
* **site**: Set to `Site.us` for US cloud projects or `Site.eu` for EU cloud projects

For additional configuration options (such as URL allowlists), see [Advanced Configuration](https://www.airship.com/docs/developer/sdk-integration/flutter/installation/advanced-configuration/).

> **Note:** Once `takeOff` is called, the config is stored and applied for future app sessions. If you call `takeOff` again with a different config, the new config will not take effect until the next app restart.


## Test the integration

After completing the setup, verify your integration to ensure everything is working correctly.

1. **Build and run your app** on both iOS and Android (if applicable):
   
   `flutter run`

2. **Check the console logs** for Airship initialization:
   * Look for log messages indicating successful SDK initialization
   * You should see a **Channel ID** in the logs—this is the unique identifier for the device

   Example log output:
   ```
   Airship takeOff succeeded
   Channel ID: 01234567-89ab-cdef-0123-456789abcdef
   ```

3. **Verify in the Airship dashboard**:
   1. Open your project.
   1. Go to **Audience**, then **Contact Management**.
   1. Search for the Channel ID from your logs. The channel should appear with the correct platform, iOS or Android.

If you don't see a channel ID or encounter errors during initialization, see the [Troubleshooting](https://www.airship.com/docs/developer/sdk-integration/flutter/troubleshooting/) guide for common problems and solutions.

## Next steps

Now that you've successfully integrated the Airship SDK:

1. [**Enable push notifications**](https://www.airship.com/docs/developer/sdk-integration/flutter/push-notifications/getting-started/) and configure notification handling
2. [**Identify users**](https://www.airship.com/docs/developer/sdk-integration/flutter/audience/contacts/) with contacts and named users
3. [**Set up Message Center**](https://www.airship.com/docs/developer/sdk-integration/flutter/message-center/getting-started/) for persistent messaging
4. [**Configure analytics**](https://www.airship.com/docs/developer/sdk-integration/flutter/data-collection/analytics/) to track user behavior

If you don't see a channel ID or encounter errors during initialization, see [Troubleshooting Initialization](https://www.airship.com/docs/developer/sdk-integration/flutter/troubleshooting/initialization/) for common problems and solutions.
