# Flutter

## Prerequisites

* This guide expects a basic [Flutter knowledge](https://flutter.dev/)
* Get a Connect3D Vendor Account from TutAR by sending a mail at <mark style="color:orange;"><<email@tutar.app>></mark>.
* Generate an API key from the [Connect3D dashboard](https://connect3d.tutar.app/dashboard)

The 3D viewer can be embedded into a Flutter app using a web view, here we are using [flutter\_inappwebview](https://inappwebview.dev/docs/5.x.x/intro/) as an example but it can be replaced with any web view library of your choice.

## Getting User Permissions

In order to enable the AR functionality, Make sure to take camera permission from the user.

{% code title="AndroidManifest.xml" %}

```markup
<manifest>
<!--
rest of the code
-->
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.webkit.PermissionRequest" />
    <uses-permission android:name="android.permission.INTERNET" />

<manifest>
```

{% endcode %}

{% code title="Info.plist" %}

```xml
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to your Camera.</string>
```

{% endcode %}

## Embedding the Viewer

Render the webview component. `mediaPlaybackRequiresUserGesture` and `allowsInlineMediaPlayback` are the required options.

<pre class="language-dart" data-title="3d_viewer.dart"><code class="lang-dart">import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class TutARWebviewWithInAppWebviewPackageScreen extends StatefulWidget {
  const TutARWebviewWithInAppWebviewPackageScreen({super.key});

  @override
  State&#x3C;TutARWebviewWithInAppWebviewPackageScreen> createState() =>
      TutARWebviewWithInAppWebviewPackageScreenState();
}

class TutARWebviewWithInAppWebviewPackageScreenState
    extends State&#x3C;TutARWebviewWithInAppWebviewPackageScreen> {
  InAppWebViewController? webViewController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Embedding with flutter_inappwebview'),
      ),
      body: InAppWebView(
              initialUrlRequest:
                  URLRequest(url: Uri.parse("https://web.tutar.app?api-key=&#x3C;<a data-footnote-ref href="#user-content-fn-1">API-KEY</a>>&#x26;user-id=&#x3C;<a data-footnote-ref href="#user-content-fn-2">USER-ID</a>>")),
              initialOptions: InAppWebViewGroupOptions(
                crossPlatform:
                    InAppWebViewOptions(mediaPlaybackRequiresUserGesture: true),
                ios: IOSInAppWebViewOptions(allowsInlineMediaPlayback: true),
              ),
              onWebViewCreated: (InAppWebViewController controller) {
                webViewController = controller;
              },
              androidOnPermissionRequest: (controller, origin, resources) async {
                return PermissionRequestResponse(
                    resources: resources,
                    action: PermissionRequestResponseAction.GRANT);
              },
            ),
      floatingActionButton: FloatingActionButton(
        mini: true,
        tooltip: 'home',
        onPressed: () {
          Navigator.pushNamed(context, "/home");
        },
        child: const Icon(Icons.home),
      ),
    );
  }
}
</code></pre>

[^1]: The key generated from the connect3D dashboad

[^2]: A unique id to distinguish each users. this can be the primary id of the logged in user in your platform


---

# 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.tutar.app/embedding/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.
