kiwi_flutter_plugin 0.0.13
kiwi_flutter_plugin: ^0.0.13 copied to clipboard
Flutter Plugin for Manual Agent Single-Call Functionality (UI Included)
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:kiwi_flutter_plugin/kiwi_flutter_plugin.dart'; // 确保路径正确
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:beep_player/beep_player.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
// 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;
}
@override
Widget build(BuildContext context) {
return MaterialApp(home: VoipPage());
}
}
class VoipPage extends StatelessWidget {
const VoipPage({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: VoipHomePage(),
);
}
}
class VoipHomePage extends StatefulWidget {
const VoipHomePage({super.key});
@override
_VoipHomePageState createState() => _VoipHomePageState();
}
class _VoipHomePageState extends State<VoipHomePage> {
// static const BeepFile _beepFile = BeepFile('assets/beep.wav');
final TextEditingController _companyIdController =
TextEditingController(text: 'a63ce0d9a5f84cf0b6eb7441f236c359');
final TextEditingController _employeeIdController =
TextEditingController(text: '7b047d69394e45a5b2c7663d2126f379');
final TextEditingController _accessTokenController = TextEditingController(
text:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTIyNDk1OTMsInVpZCI6ImI5YjJhYWI4MDE1MTRiZGQ5M2FiNjRlMGZkZjExYmY5In0.xOZM-z5w5z2unQNM5Y6kgMvFK85MXjf9puBWpGTE9gs');
final TextEditingController _mobileController =
TextEditingController(text: '18684811811');
@override
void initState() {
super.initState();
// BeepPlayer.load(_beepFile);
KiwiFlutterPlugin.signalStream.listen((data) {
Fluttertoast.showToast(msg: "调用层收到信令回调 $data", gravity: ToastGravity.TOP);
// final response = PluginResponse.fromJson(data);
// 处理消息
});
}
void _startCall() {
try {
KiwiFlutterPlugin.call(
context: context,
companyID: _companyIdController.text,
employeeID: _employeeIdController.text,
token: _accessTokenController.text,
mobile: _mobileController.text,
env: 'test');
} catch (e) {
print('无法启动 Signal 通信: $e');
}
}
void _hangUp() {
// BeepPlayer.play(_beepFile);
// 坐席侧主动挂断
KiwiFlutterPlugin.terminate();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('kiwi_flutter_plugin_example')),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: _companyIdController,
decoration: InputDecoration(labelText: 'Company ID'),
),
TextField(
controller: _employeeIdController,
decoration: InputDecoration(labelText: 'Employee ID'),
),
TextField(
controller: _accessTokenController,
decoration: InputDecoration(labelText: 'Access Token'),
),
TextField(
controller: _mobileController,
decoration: InputDecoration(labelText: 'Mobile'),
keyboardType: TextInputType.phone,
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _startCall,
child: Text('打电话'),
),
SizedBox(height: 10),
// 断开连接按钮
ElevatedButton(
onPressed: _hangUp,
child: Text('主动挂断(可选)'),
),
],
),
),
);
}
}