> For the complete documentation index, see [llms.txt](https://docs.nubrick.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nubrick.app/start/install/flutter.md).

# Flutter

## サポート環境 <a href="#requirements" id="requirements"></a>

### Android

* 実行時: Android minSdk 26 以上
* ビルド時: Android compileSdk 36 以上
* Android Gradle Plugin: 8.0 以上

### iOS

* iOS 15.0 以上
* Xcode 16.1 以上

***

## Step 1. パッケージをインストールする <a href="#step1" id="step1"></a>

<https://pub.dev/packages/nubrick_flutter> にパッケージが公開されています。

以下のコマンドを実行してパッケージをインストールしてください。

{% code title="Terminal" %}

```bash
flutter pub add nubrick_flutter
```

{% endcode %}

または、直接`pubspec.yaml`を編集し、`pub get`を実行することでもインストールできます。

{% code title="pubspec.yaml" %}

```yaml
dependencies:
  nubrick_flutter: <LATEST_VERSION>
```

{% endcode %}

{% code title="Terminal" %}

```bash
flutter pub get
```

{% endcode %}

***

## Step 2. Nubrick SDKを初期化する <a href="#step2" id="step2"></a>

{% code title="main.dart" %}

```dart
import 'package:nubrick_flutter/nubrick_flutter.dart';
import 'package:nubrick_flutter/provider.dart';
import 'package:nubrick_flutter/user.dart';

// ...

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize Nubrick Client
  Nubrick.initialize("<PROJECT_ID>");

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

class _YourAppState extends State<YourApp> {
  @override
  void initState() {
    super.initState();

    // Set user's properties to use them in the nubrick experiment
    final user = NubrickUser();
    user.setProperties({
      'prefecture': "Tokyo",
      'environment': const bool.fromEnvironment('dart.vm.product')
          ? 'production'
          : 'development',
    });
  }

  @override
  Widget build(BuildContext context) {
    // Add NubrickProvider to your root widget
    return NubrickProvider(
      child: MaterialApp(
        // ...
      ),
    );
  }
}
```

{% endcode %}

## Step 3.a (Android only) Set up Platform Specific Code

To get it working on Android, you need to make a small change to your MainActivity.kt file.

{% code title="MainActivity.kt" %}

```kt
package com.example.app

import io.flutter.embedding.android.FlutterFragmentActivity

// 1. Extend FlutterFragmentActivity instead of FlutterActivity
class MainActivity: FlutterFragmentActivity()
```

{% endcode %}

and, set the runtime requirement (`minSdk` 26 or higher) and the build requirement (`compileSdk` 36 or higher) in your `android/app/build.gradle` or `android/app/build.gradle.kts` file.

{% tabs %}
{% tab title="Gradle (Groovy)" %}
`android/app/build.gradle` に以下を追加します。

```groovy
android {
    compileSdk 36

    defaultConfig {
        // Set the minimum sdk version to 26
        minSdkVersion 26
    }
}
```

{% endtab %}

{% tab title="Gradle (Kotlin DSL)" %}
`android/app/build.gradle.kts` に以下を追加します。

```kotlin
android {
    compileSdk = 36

    defaultConfig {
        // Set the minimum sdk version to 26
        minSdk = 26
    }
}
```

{% endtab %}
{% endtabs %}

finally, set the kotlin version to >= 1.9.10 in your `android/settings.gradle` or `android/settings.gradle.kts` file.

{% tabs %}
{% tab title="Gradle (Groovy)" %}
`android/settings.gradle` に以下を追加します。

```groovy
plugins {
    // ...
    id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}
```

{% endtab %}

{% tab title="Gradle (Kotlin DSL)" %}
`android/settings.gradle.kts` に以下を追加します。

```kotlin
plugins {
    // ...
    id("org.jetbrains.kotlin.android") version "1.9.10" apply false
}
```

{% endtab %}
{% endtabs %}

## Step 3.b. (iOS only) Set up Platform Specific Code

To get it working on iOS, you need to change a minimum deployments to 15.0 in your ios/Runner.xcodeproj/project.pbxproj file.

1. In Xcode, navigate to `Runner.xcodeproj > TARGETS > Runner > General > Minimum Deployments`
2. Change the `minimum deployments` to `15.0`

Once you're finished, you can start using Nubrick.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.nubrick.app/start/install/flutter.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
