Onur
07/11/2024, 8:45 AMVapi
07/11/2024, 8:46 AMVapi
07/11/2024, 8:46 AMOnur
07/11/2024, 8:53 AMdart
Future<void> test() async {
setState(() {
buttonText = 'Loading...';
isLoading = true;
});
try {
if (!isCallStarted) {
await vapi.start(assistantId: VAPI_ASSISTANT_ID);
} else {
await vapi.stop();
}
} catch (err) {
print(err);
}
}
}
@UserShubham Bajaj
07/11/2024, 3:45 PMOnur
07/11/2024, 3:46 PMOnur
07/12/2024, 12:01 PMShubham Bajaj
07/12/2024, 12:04 PMOnur
07/12/2024, 12:05 PMdart
class VapiTest extends StatefulWidget {
const VapiTest({super.key});
@override
_VapiTestState createState() => _VapiTestState();
}
class _VapiTestState extends State<VapiTest> {
late StreamSubscription _subscription;
@override
void initState() {
super.initState();
_subscription = vapi.onEvent.listen((event) {
if (event.label == 'call-start') {
setState(() {
buttonText = 'End Call';
isLoading = false;
isCallStarted = true;
});
print('call started');
}
if (event.label == 'call-end') {
setState(() {
buttonText = 'Start Call';
isLoading = false;
isCallStarted = false;
});
print('call ended');
}
if (event.label == 'message') {
print(event.value);
}
});
}
@override
void dispose() {
_subscription.cancel();
super.dispose();
}
String buttonText = 'Start Call';
bool isLoading = false;
bool isCallStarted = false;
Vapi vapi = Vapi(VAPI_PUBLIC_KEY);
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: isLoading ? null : test,
child: Text(buttonText),
);
}
Future<void> test() async {
setState(() {
buttonText = 'Loading...';
isLoading = true;
});
try {
if (!isCallStarted) {
await vapi.start(assistantId: VAPI_ASSISTANT_ID);
} else {
await vapi.stop();
}
} catch (err) {
print(err);
}
}
}
Also we are using
flutter 3.22.2
Vapi 0.0.9
We had do to a dependecy override for permission_handler to version 11.0.0 since we are using a newer versionOnur
07/15/2024, 7:30 AMShubham Bajaj
07/15/2024, 8:02 AMShubham Bajaj
07/15/2024, 8:02 AMOnur
07/15/2024, 9:30 AMShine
01/08/2025, 4:02 AMShubham Bajaj
01/08/2025, 4:29 PMShine
01/08/2025, 4:31 PMShine
01/09/2025, 1:29 PMShubham Bajaj
01/09/2025, 10:43 PM