dt_aiui_plugin 1.0.0 copy "dt_aiui_plugin: ^1.0.0" to clipboard
dt_aiui_plugin: ^1.0.0 copied to clipboard

A new flutter plugin project.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

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

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  bool _platformVersion = false;
  String _eventContent = "nothing";
  EventChannel _eventChannel;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    bool platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    _eventChannel = DtAiuiPlugin.eventChannel;

    _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);

    try {
      platformVersion = await DtAiuiPlugin.initAIUIAgent("5face485"); // 填写自己的appid
    } on PlatformException {
      platformVersion = false;
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  void _onEvent(Object object){
    setState(() {
      if (object is String) {
        _eventContent = object;
      }
    });
  }

  void _onError(Object object){
    setState(() {
      if (object is String) {
        _eventContent = object;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: SingleChildScrollView(
            child: Column(
              children: [
                Container(
                  margin: EdgeInsets.all(20),
                  child: GestureDetector(
                    onTap: (){
                      DtAiuiPlugin.startVoiceNlp;
                    },
                    child: Text('start voice nlp'),
                  ),
                ),
                Container(
                  margin: EdgeInsets.all(20),
                  child: GestureDetector(
                    onTap: (){
                      DtAiuiPlugin.stopVoiceNlp;
                    },
                    child: Text('stop voice nlp'),
                  ),
                ),
                Container(
                  margin: EdgeInsets.all(20),
                  child: Text(_eventContent),
                )
              ],
            ),
          )
      ),
    );
  }
}
0
likes
100
pub points
20%
popularity

Publisher

unverified uploader

A new flutter plugin project.

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on dt_aiui_plugin