sense_flutter_plugin : 2.0.1 // signal
sense_behaviour_flutter_plugin : 0.0.1 //Behaviourimport 'package:sense_flutter_plugin/sense_flutter_plugin.dart';
import 'package:sense_behaviour_flutter_plugin/sense_behaviour_flutter_plugin.dart';//For Device Security
Sense.initSDK({
"publicKey": "YOUR_PUBLIC_KEY",
"senseInfo": true,
"allowGeoLocation": false,
"tag": "HomeFlutter"
});
Sense.getSenseDetails();
//For Behavior SDK
SenseBehaviourRoot(
child: MyApp(), // Your App Widget
),
SenseBehaviourFlutter.initSDK(
apiKey: 'YOUR_PUBLIC_KEY',
sense_request_id : "SENSE_REQUEST_ID", // Your request id you get from the Sense Device Security SDK
context: context,
inputControllers: [ // Your input controllers
nameController,
colorController,
],
);//For Behavior SDK - App Widget
SenseBehaviourRoot(
child: MyApp(), // Your App Widget
),
//Sample Program
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sense_behaviour_flutter_plugin/sense_behaviour_flutter_plugin.dart';
import 'package:sense_flutter_plugin/sense_flutter_plugin.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late final TextEditingController nameController;
late final TextEditingController colorController;
final sense = Sense();
@override
void initState() {
super.initState();
sense.initSDK({
"publicKey": "YOUR_PUBLIC_KEY",
"senseInfo": true,
"allowGeoLocation": false,
"tag": "HomeFlutter"
});
getDetails();
}
Future<void> getDetails() async {
var response = await sense.getSenseDetails();
bool success = response["success"];
String message = response["message"];
String? data = response["data"];
Map<String, dynamic> senseInfo = jsonDecode(data.toString());
if(success){
nameController = TextEditingController();
colorController = TextEditingController();
SenseBehaviourFlutter.initSDK(
apiKey: 'YOUR_PUBLIC_KEY',
reference_id: 'REF_001',
sense_request_id : senseInfo['request_id'],
context: context,
inputControllers: [
nameController,
colorController,
],
);
}
}
@override
void dispose() {
nameController.dispose();
colorController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BehaviourScreen(
nameController: nameController,
colorController: colorController,
);
}
}
class BehaviourScreen extends StatefulWidget {
final TextEditingController nameController;
final TextEditingController colorController;
const BehaviourScreen({super.key, required this.nameController,required this.colorController});
@override
State<BehaviourScreen> createState() => _BehaviourScreenState();
}
class _BehaviourScreenState extends State<BehaviourScreen> {
bool showResult = false;
bool showLoader = false;
String str = "";
double loanAmount = 10000;
String tenure = "12";
bool agree = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF4F4F7),
appBar: AppBar(
backgroundColor: const Color(0xFFFFFFFF),
scrolledUnderElevation: 0,
title: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
'assets/images/sense.png',
fit: BoxFit.contain,
height: 40,
),
),
),
),
body: Stack(
children: [
if (!showResult)
SingleChildScrollView(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Behaviour Analysis",
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Color(0xFF6941C6)
),
),
const SizedBox(height: 12),
const Text(
"Personal Details",
style: TextStyle(
fontSize: 18, fontWeight:FontWeight.bold
),
),
const SizedBox(height: 12),
const Text(
"Full Name",
style: TextStyle(
fontSize: 14, color: Color(0xFF6941C6)
),
),
const SizedBox(height: 6),
TextField(
controller: widget.nameController,
decoration: const InputDecoration(
hintText: 'Full Name',
),
),
const SizedBox(height: 12),
const Text(
"Favourite Color",
style: TextStyle(
fontSize: 14, color: Color(0xFF6941C6)
),
),
const SizedBox(height: 6),
TextField(
controller: widget.colorController,
decoration: const InputDecoration(
hintText: 'Favourite Color',
),
),
],
),
),
// Loan Amount
_card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Loan Amount",
style: TextStyle(
fontSize: 18, fontWeight:FontWeight.bold
),
),
const SizedBox(height: 16),
Text(
"₹${loanAmount.toInt()}",
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Color(0xFF6941C6)
),
),
Slider(
min: 10000,
max: 200000,
divisions: 190,
value: loanAmount,
onChanged: (v) =>
setState(() => loanAmount = v),
),
const Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text("₹10,000",
style:
TextStyle(color:
Color(0xFF9193A0))),
Text("₹200,000",
style:
TextStyle(color:
Color(0xFF9193A0))
),
],
)
],
),
),
// Tenure
_card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Choose Tenure",
style: TextStyle(
fontSize: 18, fontWeight:
FontWeight.bold
),
),
RadioListTile(
title: const Text("12 Months"),
value: "12",
groupValue: tenure,
onChanged: (v) =>
setState(() => tenure = v.toString()),
),
RadioListTile(
title: const Text("18 Months"),
value: "18",
groupValue: tenure,
onChanged: (v) =>
setState(() => tenure = v.toString()),
),
RadioListTile(
title: const Text("24 Months"),
value: "24",
groupValue: tenure,
onChanged: (v) =>
setState(() => tenure = v.toString()),
),
],
),
),
// Terms
_card(
child: Row(
children: [
const Expanded(
child: Text(
"I agree to the terms & conditions",
style: TextStyle(fontSize: 15),
),
),
Switch(
value: agree,
onChanged: (v) => setState(() => agree = v),
)
],
),
),
// Submit
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF6941C6),
foregroundColor: Colors.white,
minimumSize: const Size.fromHeight(54),
),
onPressed: () async {
final result = await
SenseBehaviourFlutter.getBehaviourData();
setState(() {
showLoader = false;
showResult = true;
str = result.toString();
});
},
child: const Text("Submit Application"),
),
// RESULT SCREEN
if (showResult)
SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 20),
// COPY BUTTON
Align(
alignment: Alignment.centerLeft,
child: ElevatedButton.icon(
icon: const Icon(Icons.copy, size: 18),
label: const Text('Back'),
onPressed: () =>; setState(() =>; showResult = false),
),
),
Align(
alignment: Alignment.centerRight,
child: ElevatedButton.icon(
icon: const Icon(Icons.copy, size: 18),
label: const Text('Copy'),
onPressed: () {
copyStringAsPrettyJson(context, str);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Copied to clipboard'),
duration: Duration(seconds: 1),
),
);
},
),
),
const SizedBox(height: 12),
// RESULT CARD
Container(
padding: const EdgeInsets.all(16),
decoration: _cardDecoration(),
child: SelectableText(
str,
style: const TextStyle(fontFamily:'monospace'),
),
),
const SizedBox(height: 24),
],
),
),
if (showLoader)
const Center(child: CircularProgressIndicator()),
],
),
);
]
)
}
}
BoxDecoration _cardDecoration() {
return BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
);
}
Widget _card({required Widget child}) {
return Container(
margin: const EdgeInsets.only(bottom: 20),
padding: const EdgeInsets.all(20),
decoration: _cardDecoration(),
child: child,
);
}
Future<void> copyStringAsPrettyJson(
BuildContext context,
String rawString,
) async {
try {
final decoded = jsonDecode(rawString);
final prettyJson =
const JsonEncoder.withIndent('').convert(decoded);
await Clipboard.setData(ClipboardData(text: prettyJson));
_showCopied(context);
} catch (_) {
await Clipboard.setData(ClipboardData(text: rawString));
_showCopied(context);
}
}
void _showCopied(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Copied to clipboard"),
duration: Duration(seconds: 1),
),
);
}
}