conva_omni_copilot 1.4.3 copy "conva_omni_copilot: ^1.4.3" to clipboard
conva_omni_copilot: ^1.4.3 copied to clipboard

The client library for adding and interacting with CONVA OMNI Copilot.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';

import 'package:conva_omni_copilot/conva_omni_copilot.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(new MaterialApp(
    home: new MyApp(),
    debugShowCheckedModeBanner: false,
  ));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp>
    implements CopilotAction, CopilotLifeCycleObserver {
  String _displayText = '';

  @override
  void initState() {
    super.initState();
    initConvaOmniCopilot();
  }

  void initConvaOmniCopilot() {
    List<List<String>> waveGradientColor = [
      ["#0197FF", "#FFFFFF"],
      ["#9701FF", "#FF0197"],
      ["#FF0197", "#FF9701"],
    ];
    var assistantConfig = new OmniCopilotConfiguration()
      ..copilotId = "<CopilotId>"
      ..apiKey = "<ApiKey>"
      ..enableCustomTrigger = true
      ..fontPaths = [
        "fonts/TerminalDosis-Regular.ttf",
        "fonts/TerminalDosis-SemiBold.ttf"
      ]
      ..waveGradientColor = waveGradientColor;

    ConvaOmniCopilot.initialize(assistantConfig);
    ConvaOmniCopilot.setLifeCycleObserver(this);
    ConvaOmniCopilot.setAction(this);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: AppBar(
              title: const Text('CONVA Omni Copilot'),
            ),
            body: Center(
                child: Column(
              mainAxisSize: MainAxisSize.max,
              children: [
                Container(height: 25),
                Row(
                  children: [
                    Expanded(
                      child: Container(
                          height: 45.0,
                          margin:
                              const EdgeInsets.fromLTRB(17.0, 0.0, 10.0, 0.0),
                          child: TextField(
                            controller: TextEditingController(text: ""),
                            decoration: InputDecoration(
                              labelText: 'Utterance Text',
                              suffixIcon: GestureDetector(
                                onTap: () {
                                  Clipboard.setData(
                                      ClipboardData(text: _displayText));
                                  ScaffoldMessenger.of(context).showSnackBar(
                                    const SnackBar(
                                        content: Text('Utterance text copied')),
                                  );
                                },
                                child: Icon(Icons.copy),
                              ),
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(10.0),
                                borderSide: const BorderSide(
                                  color: Colors.blue,
                                  width: 2.0,
                                ),
                              ),
                            ),
                          )),
                    ),
                    Container(
                      height: 60,
                      width: 60,
                      margin: const EdgeInsets.only(right: 10.0),
                      child: Padding(
                          padding: const EdgeInsets.all(
                              8.0), // Adjust the padding as needed
                          child: ConvaOmniTrigger(
                            enableCircularBackground: true,
                          )),
                    ),
                  ],
                ),
                Container(height: 30), // set height
                Flexible(
                    child: FractionallySizedBox(
                        widthFactor: 0.9,
                        heightFactor: 0.98,
                        child: SingleChildScrollView(
                            physics: const AlwaysScrollableScrollPhysics(),
                            child: Container(
                              height: MediaQuery.of(context).size.height,
                              decoration: const BoxDecoration(
                                shape: BoxShape.rectangle,
                                color: Colors.black,
                              ),
                              child: Padding(
                                padding: const EdgeInsets.all(16.0),
                                child: Text(
                                  '$_displayText\n',
                                  style: const TextStyle(
                                      fontSize: 20.0,
                                      fontWeight: FontWeight.bold,
                                      color: Colors.white),
                                ),
                              ),
                            ))))
              ],
            ))));
  }

  @override
  void onCopilotInitFailure(String description) {
    print("onCopilotInitFailure " + description);
  }

  @override
  void onCopilotInitSuccess() {
    print("onCopilotInitSuccess");
  }

  @override
  void onCopilotInteractionBegin(bool isVoice) {
    print("onCopilotInteractionBegin");
  }

  @override
  void onCopilotInteractionEnd(bool isCanceled) {
    print("onCopilotInteractionEnd");
  }

  @override
  void onCopilotSurfaceDismissed() {
    print("onCopilotSurfaceDismissed");
  }

  @override
  void onCopilotError(CopilotError error) {
    if (error.errorType == ErrorType.UNINITIALIZED_USAGE_ERROR) {
      print("UNINITIALIZED_USAGE_ERROR");
    }
  }

  @override
  void onNavigation(NavigationInfo navigationInfo) {
    setState(() {
      try {
        JsonEncoder encoder = const JsonEncoder.withIndent('  ');
        String navigationMapString = encoder.convert(navigationInfo);
        _displayText = navigationMapString.toString();
      } catch (e) {
        print(e);
      }
    });
  }

  @override
  void onSearch(SearchInfo searchInfo) {
    setState(() {
      try {
        JsonEncoder encoder = const JsonEncoder.withIndent('  ');
        String searchMapString = encoder.convert(searchInfo);
        _displayText = searchMapString.toString();
      } catch (e) {
        print(e);
      }
    });
  }
}
2
likes
140
points
7.02k
downloads

Publisher

verified publisherslanglabs.in

Weekly Downloads

The client library for adding and interacting with CONVA OMNI Copilot.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on conva_omni_copilot