> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pnlight.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Flutter SDK

> Install the pnlight_sdk Flutter package, configure the iOS Podfile and Info.plist, and initialize the PNLight SDK in your Flutter app for iOS.

Use `pnlight_sdk` for Flutter apps that need PNLight on iOS.

## Requirements

* Flutter 3.3.0+
* Dart 2.17.0 or later, below 4.0.0
* iOS 12.0+

## Install

Add the package:

```bash theme={null}
flutter pub add pnlight_sdk
```

Package page: [pnlight\_sdk on pub.dev](https://pub.dev/packages/pnlight_sdk).

[![Flutter SDK version](https://img.shields.io/pub/v/pnlight_sdk?label=Flutter)](https://pub.dev/packages/pnlight_sdk)

## iOS setup

If you use `RemoteUiView`, add the DivKit CocoaPods source to `ios/Podfile` before other sources:

```ruby theme={null}
source 'https://github.com/divkit/divkit-ios.git'
```

If your app collects IDFA on iOS 14.0+, add `NSUserTrackingUsageDescription` to `Info.plist`:

```xml theme={null}
<key>NSUserTrackingUsageDescription</key>
<string>This app uses device tracking to support attribution and analytics.</string>
```

## Initialize the SDK

```dart theme={null}
import 'package:pnlight_sdk/pnlight_sdk.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await PNLightSDK.initialize('pnlight_sdk_token');

  runApp(const MyApp());
}
```

## Common calls

```dart theme={null}
final success = await PNLightSDK.addAttribution(
  provider: 'appsFlyer',
  data: {'af_status': 'Non-organic'},
  identifier: 'appsFlyerCustomerId',
);

await PNLightSDK.logEvent('paywall_viewed', {
  'placement': 'paywall',
});
```

`logEvent` sends optional in-app events to PNLight. You can review them in **Analytics → App Events**, on the **Events** page, and in customer timelines.

## IDFA after ATT

If PNLight initializes before the App Tracking Transparency prompt completes, call `updateIdfa()` after authorization so PNLight receives the granted IDFA.

```dart theme={null}
import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:pnlight_sdk/pnlight_sdk.dart';

await AppTrackingTransparency.requestTrackingAuthorization();
await PNLightSDK.updateIdfa();
```

## Remote UI

```dart theme={null}
import 'package:pnlight_sdk/pnlight_sdk.dart';

RemoteUiView(
  placement: 'paywall',
  cardId: 'paywall_card',
  ignoreCache: false,
  onAction: (RemoteUiActionEvent event) async {
    if (event.path == 'purchase') {
      final success = await startPurchase(event.params['id']);
      if (success) {
        openMainScreen();
      }
    }
  },
  onError: (Object error) {
    // Show a local fallback or close the screen.
  },
)
```

<Note>
  The Flutter package wraps the PNLight iOS SDK. Do not call PNLight SDK methods on unsupported platforms.
</Note>
