slang_bfsi_assistant 2.0.2
slang_bfsi_assistant: ^2.0.2 copied to clipboard
The client library for adding and interacting with Slang CONVA's BFSI In-App Voice Assistant.
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:slang_bfsi_assistant/slang_bfsi_assistant.dart';
void main() {
runApp(const MaterialApp(
home: MyApp(),
debugShowCheckedModeBanner: false,
));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _stockInfo = 'Stock Search Info appears here';
@override
void initState() {
super.initState();
initSlangAssistant();
}
void initSlangAssistant() {
//Obtain the AssistantId and APIKey for the given assistant
var assistantConfig = AssistantConfiguration()
..assistantId = "<AssistantId>"
..apiKey = "<APIKey>";
//Initialize the SDK using the configurations specified above
SlangBFSIAssistant.initialize(assistantConfig);
//Enable the slang trigger to be shown on the screen.
SlangBFSIAssistant.getUI().showTrigger();
//Obtain the callback related to stock search and perform the required action.
SlangBFSIAssistant.setOnStockSearchListener(
(stockInfo, searchUserJourney) => {
//Use stockInfo to perform the stock search operation.
print(stockInfo.name),
print(stockInfo.bseCode),
print(stockInfo.nseCode),
print(stockInfo.isinNumber),
print(stockInfo.customId),
print(stockInfo.action),
print(stockInfo.utterance),
//Setting the state variable as an example to showcase the json representation of the stock search object.
setState(() {
try {
JsonEncoder encoder = const JsonEncoder.withIndent(' ');
String searchMapString = encoder.convert(stockInfo);
_stockInfo = searchMapString;
} catch (e) {
print(e);
}
})
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Slang BFSI PlayGround App'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(height: 16), // set height
Flexible(
child: FractionallySizedBox(
widthFactor: 0.9,
heightFactor: 0.7,
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(
'$_stockInfo\n',
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
))))
],
))));
}
}