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

# How Do I Initialize the Flutter SDK (v4)?

> Initialize Gameball Flutter SDK with your configuration

# Initialize the SDK

Initialize Gameball once, usually at app startup in your `main()` function:

🔒

**Secure API Access:** To benefit from v4.1 secure API endpoints, pass the `sessionToken` parameter during SDK initialization (required in upcoming SDK v4). This enables automatic routing to v4.1 secure endpoints. [Learn more about v4.1 →](https://docs.gameball.co/api-reference/introduction-v4.1.md)

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

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

  final config = GameballConfigBuilder()
      .apiKey("your-api-key")          // Required
      .lang("en")                      // Required
      .platform("flutter")             // Optional
      .shop("your-shop-id")            // Optional
      .sessionToken("your-session-token") // Optional - for v4.1 endpoints
      .build();

  final gameballApp = GameballApp.getInstance();
  gameballApp.init(config);

  runApp(MyApp());
}
```

## Configuration Parameters

**apiKey** `string` *required*

The client API key available in your Gameball dashboard (required).

**lang** `string` *required*

The language code for SDK localization (e.g., "en", "ar", "fr"). Required.

**platform** `string`

Platform identifier, defaults to "flutter".

**shop** `string`

Your Gameball shop identifier for multi-shop configurations.

**sessionToken** `string`

Session Token for secure authentication (enables automatic v4.1 endpoint routing). Required in upcoming SDK v4.

### Validation Rules

**GameballConfig requires:**

* API key is required (cannot be null)
* Language is required (cannot be null)

## Example

```dart theme={null}
import 'package:flutter/material.dart';
import 'package:gameball_sdk/gameball_sdk.dart';

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

  // Initialize Gameball SDK
  final config = GameballConfigBuilder()
      .apiKey("gb_live_xxxxxxxxxxxxxxxx")
      .lang("en")
      .platform("flutter")
      .shop("myshop")
      .sessionToken("your-session-token")  // Optional
      .build();

  final gameballApp = GameballApp.getInstance();
  gameballApp.init(config);

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Gameball Demo',
      home: HomeScreen(),
    );
  }
}
```

> [!TIP]
>
> Call `init()` before running your app to ensure the SDK is ready when your app starts.

> [!WARNING]
>
> Make sure to use your actual API key from the Gameball dashboard. Test keys are for development, production keys are for live deployment.

## Next Steps

* [Initialize Customer Profile](https://docs.gameball.co/installation-guides/v4/flutter/initialize-profile.md)
* [Track Customer Events](https://docs.gameball.co/installation-guides/v4/flutter/track-events.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.