# CrossIndie Flutter SDK

## Concepts

- **app_id**: the id of your app, shown in the dashboard under My Apps (https://crossindie.com/dashboard/apps). It is public; it goes into your app, game or site code.
- **App API key** (`api_key`): secret, used only for the account API and the MCP server. Never put it in a shipped app, game or web page.
- **api_base**: `https://api.crossindie.com`.
- **category**: `game`, `web_tool`, `saas` or `mobile_app`. Games are shown only to games; web tools and SaaS share a pool.
- Every placed banner is an independent earning slot. An impression only counts after the banner has been visible for at least 1.5 seconds (while the window or app is focused). All credit and anti-fraud checks run on the server.
- New apps may need review before they are served. Check the app status in the dashboard.
- An app is promoted only once it is live on a store. For Google Play and App Store links the package (`play_package`) or numeric id (`appstore_id`) is derived from `target_url`; CrossIndie checks store liveness every 12 hours and shows `store_status` (live, not_found, error, unknown). Web apps do not need a store listing.

## Install

Not on pub.dev yet. Add a git dependency in `pubspec.yaml`, then run `flutter pub get`:

```yaml
dependencies:
  crossindie:
    git:
      url: https://github.com/Cross-Indie/sdks.git
      path: flutter
```

Dependencies: `http` and `url_launcher` only. Android release builds need `<uses-permission android:name="android.permission.INTERNET"/>` in `android/app/src/main/AndroidManifest.xml`.

## Usage

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

const CrossIndieBanner(appId: 'YOUR_APP_ID')
```

Parameters: `appId` (required), `category` (`CrossIndieCategory.game | webTool | saas | mobileApp`, default mobileApp), `format` (`CrossIndieFormat.card | rectangle | leaderboard | mobile | text`, default card), `apiBase` (default `https://api.crossindie.com`), `packageName` (optional String), `country`, `lang`, `closeable` (default true), `refreshInterval` (Duration?, null = no rotation, min 30 s), callbacks `onAdLoaded(CrossIndieAd)`, `onNoAd()`, `onImpression(CrossIndieAd)`, `onClick(CrossIndieAd)`, `onError(Object)`.

```dart
CrossIndieBanner(
  appId: 'YOUR_APP_ID',
  category: CrossIndieCategory.game,
  format: CrossIndieFormat.mobile, // 320 x 50
  packageName: info.packageName,    // e.g. from package_info_plus (optional)
)
```

## Pitfalls

- The widget renders nothing until an ad arrives (and nothing at all on errors or when there is no ad). Do not reserve fixed space you then cover.
- Pure Dart cannot read the package name, so pass `packageName` if you want the dashboard to confirm the SDK runs inside your store app.
- Impressions need at least 50% of the banner on screen (and inside any scroll view), the app resumed and its route on top, continuously for 1.5 s.
- Clicks open the external browser via url_launcher.
