# Examples

## AutoFetch True:&#x20;

```dart
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';

class OnairosApp extends StatefulWidget {
  @override
  _OnairosAppState createState() => _OnairosAppState();
}

class _OnairosAppState extends State<OnairosApp> {
  final Map<String, dynamic> requestData = {
    "Small": {
      "type": "Personality",
      "descriptions": "Insight into your Interests",
      "reward": "10% Discount",
    },
    "Medium": {
      "type": "Personality",
      "descriptions": "Insight into your Interests",
      "reward": "2 USDC",
    },
    "Large": {
      "type": "Personality",
      "descriptions": "Insight into your Interests",
      "reward": "2 USDC",
    },
  };

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Onairos Demo'),
      ),
      body: Center(
        child: OnairosButtonWrapper1(
          webpageName: 'Mobile App',
          requestData: requestData,
          returnLink: 'yourapp://returnlink',
          autoFetch: true,
          onResolved: onResolved, //Function which recieves the users Personality Data
          inferenceData: {}, // Inference data.
          proofMode: false,
          textColor: 'black', // Example color
          textLayout: 'right', // Replace with actual text layout configuration
        ),
      ),
    );
  }
}

 
```

## AutoFetch False (Manual API Call):

<pre class="language-dart"><code class="lang-dart"><strong>import 'package:flutter/material.dart';
</strong>import 'package:http/http.dart' as http;
import 'dart:convert';

class OnairosApp extends StatefulWidget {
  @override
  _OnairosAppState createState() => _OnairosAppState();
}

class _OnairosAppState extends State&#x3C;OnairosApp> {
  Future&#x3C;void> onResolved(String apiUrl, String accessToken) async {
    try {
      final response = await http.post(
        Uri.parse(apiUrl),
        headers: {
          "Authorization": "Bearer $accessToken",
          "Content-Type": "application/json",
        },
        body: jsonEncode(requestData),
      );

      if (response.statusCode == 200) {
        final Map&#x3C;String, dynamic> data = jsonDecode(response.body);
        // Process Onairos Data
        print("Data: $data");
      } else {
        // Handle error response
        print("Error: ${response.statusCode}");
      }
    } catch (e) {
      print("Exception: $e");
    }
  }

  final Map&#x3C;String, dynamic> requestData = {
    "Small": {
      "type": "Personality",
      "descriptions": "Insight into your Interests",
      "reward": "10% Discount",
    },
    "Medium": {
      "type": "Personality",
      "descriptions": "Insight into your Interests",
      "reward": "2 USDC",
    },
    "Large": {
      "type": "Personality",
      "descriptions": "Insight into your Interests",
      "reward": "2 USDC",
    },
  };

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Onairos Demo'),
      ),
      body: Center(
        child: OnairosButtonWrapper1(
          webpageName: 'Mobile App',
          requestData: requestData,
          returnLink: 'yourapp://returnlink',
          autoFetch: true,
          onResolved: onResolved,
          inferenceData: {}, // Assuming this is a placeholder or real data.
          proofMode: false,
          textColor: Colors.black, // Example color
          textLayout: TextLayout(), // Replace with actual text layout configuration
        ),
      ),
    );
  }
}
</code></pre>
