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

outdated

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.
    try {
      platformVersion = await DtAiuiPlugin.initAIUIAgent("*****"); // 填写自己的appid
    } on PlatformException {
      platformVersion = false;
    }
  _eventChannel = DtAiuiPlugin.eventChannel;
    _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    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
0
pub points
9%
popularity

Publisher

unverified uploader

A new flutter plugin project.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on dt_aiui_plugin