# Flutter

<mark style="color:orange;">**Installation**</mark>

#### Use [this](https://pub.dev/packages/flutter_conscent_plugin/install) package as a library

Depend on it

Run this command with Flutter:

```bash
flutter pub add flutter_conscent_plugin
```

This will add a line like this to your package's pubspec.yaml (and run an implicit `flutter pub get`):

```yaml
dependencies:
  flutter_conscent_plugin: ^0.4.2
```

Alternatively, your editor might support `flutter pub get`. Check the docs for your editor to learn more.

#### Import it

Now in your Dart code, you can use:

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

<details>

<summary><mark style="color:orange;">Initialize SDK</mark></summary>

In your application pass these fields in your app.

* client\_id - Pass your clientId received from Conscent.ai.
* ENVIRONMENTMODE -  configuration testing of different environments available.&#x20;

```dart
ENVIRONMENTMODE can be set as :
    ENVIRONMENTMODE.SANDBOX 
    ENVIRONMENTMODE.PRODUCTION
```

The below code can be used as a sample:

```dart
ConscentInitializer("your_client_id", ENVIRONMENTMODE.SANDBOX);
```

</details>

<mark style="color:orange;">**Initialize Paywall**</mark>

1. Pass client content id in **setContentId(clientContentId)** Method:

Attaching the code below for the refernce:

```dart
ConscentInitializer.setContentId('your_content_id');
```

2. Check content access and show the paywall:

```dart
bool showContent = false;

 FutureBuilder<bool>(
  future: ConscentMethods().getContentAccess(),
  builder: (context, snapshot){
  
  if (snapshot.hasData) {
       var responseData = snapshot.data;
         if (responseData != null) {
           showContent = responseData;
         }
       
       return Center(
                  child: Stack(
                    children: <Widget>[
                      SingleChildScrollView(
                        controller: scrollController,
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          height: MediaQuery.of(context).size.height,
                          padding: const EdgeInsets.all(20.0),
                          alignment: Alignment.topCenter,
                          child: YourContentPage(),
                        ),
                      ),
                      if (!showContent)
                        Container(
                            width: MediaQuery.of(context).size.width,
                            height: MediaQuery.of(context).size.height,
                            alignment: Alignment.bottomCenter,
                            child: Paywall((response) {
                              if (responseData != null) {
                                  showContent = responseData;
                              }
                              setState(() {});
                            })),
                    ],
                  ),
                );
               
  }else if (snapshot.hasError) {
    return ShowYourErrorPage();
  }
 },
), 
```

> *<mark style="color:orange;">These methods need to be called on the Content Page.</mark>*

<mark style="color:orange;">**Handling Events**</mark>

1. **Scroll Listener Event**

```dart
scrollController.addListener(() {
      onScollDepth = max(scrollController.offset, onScollDepth);
      height = scrollController.position.maxScrollExtent;

      ConscentMethods().setScollDepthHeight(onScollDepth, height);

      ConscentMethods().onTouchListener();
    });
```

2. **Exit from the Content page**

```dart
@override
void dispose() {
  super.dispose();
  ConscentMethods().pageExitEvent();
}
```

#### The below method is called to Logout from Conscent.ai

```dart
ConscentMethods().userLogOut()
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.conscent.ai/version-1.0/mobile-sdk/flutter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
