flutter_intelligence_sign3 2.1.2
flutter_intelligence_sign3: ^2.1.2 copied to clipboard
The Sign3 SDK detects device risks like rooting, VPNs, and remote access, providing insights to enhance fraud protection.
example/lib/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_intelligence_sign3/flutter_intelligence_sign3.dart';
import 'package:flutter_intelligence_sign3/model/options.dart';
import 'package:flutter_intelligence_sign3/model/update_options.dart';
import 'package:flutter_intelligence_sign3_example/utils/log.dart';
import 'package:geolocator/geolocator.dart';
import 'json_viewer.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String initValue = "";
String stop = "";
String sessionID = "";
var jsonData = <String, dynamic>{};
@override
void initState() {
super.initState();
requestLocationPermission();
initSign3Sdk();
}
Future<void> requestLocationPermission() async {
LocationPermission permission;
// Check if location services are enabled
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
// Location services are not enabled, request the user to enable them
return Future.error('Location services are disabled.');
}
// Check the current permission status
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
// Request permission if it is denied
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
// Permissions are denied, handle appropriately
return Future.error('Location permissions are denied');
}
}
if (permission == LocationPermission.deniedForever) {
// Permissions are permanently denied, handle appropriately
return Future.error('Location permissions are permanently denied, we cannot request permissions.');
}
// When permissions are granted, you can access the location
Position position = await Geolocator.getCurrentPosition();
print('Current position: $position');
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Sign3 SDK Flutter'),
),
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.vertical,
child: Container(
child: Column(
children: [
Text("INIT: $initValue"),
Text("STOP: $stop"),
Text("SESSION ID: $sessionID"),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
ElevatedButton(
onPressed: () async {
await initSign3Sdk();
},
child: const Text("Init Sdk")
),
ElevatedButton(
onPressed: () async {
await getIntelligence();
},
child: const Text("Get Intelligence")
),
ElevatedButton(
onPressed: () async {
showCustomDialog(context);
},
child: const Text("Update Options")
),
],
),
),
SizedBox(
height: jsonData.keys.length * JsonViewer.textSize * 40 ,
child: Padding (
padding: const EdgeInsets.all(8.0),
child: JsonViewer(jsonData: jsonData),
),
),
SizedBox(
width: 1,
height: 50,
child: Container(),
),
],
),
),
),
),
);
}
void showCustomDialog(BuildContext context) {
TextEditingController phoneController = TextEditingController();
TextEditingController idController = TextEditingController();
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Update Options'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: phoneController,
decoration: const InputDecoration(
labelText: 'Set Phone Number',
),
keyboardType: TextInputType.number, // Set to number input type
),
const SizedBox(height: 10),
TextField(
controller: idController,
decoration: const InputDecoration(
labelText: 'Set ID',
),
keyboardType: TextInputType.number, // Set to number input type
),
],
),
actions: [
ElevatedButton(
onPressed: () async {
if (phoneController.text.isEmpty || idController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Both fields must be filled out.'),
),
);
return;
}
await updateOptions(getUpdatedOptions(phoneController.text, idController.text));
await getIntelligence();
Navigator.of(context).pop();
},
child: const Text('Update Options'),
),
],
);
},
);
}
UpdateOptions getUpdatedOptions(String phone, String id) {
Map<String, String> additionalAttributes = {
"TRANSACTION_ID": "76381256165476154713",
"DEPOSIT": "5000",
"WITHDRAWAL": "2000",
"METHOD": "UPI",
"STATUS": "SUCCESS",
"CURRENCY": "INR",
"TIMESTAMP": DateTime.now().millisecondsSinceEpoch.toString(),
};
UpdateOptions updateOptions = UpdateOptionsBuilder()
.setPhoneNumber(phone)
.setUserId(id)
.setPhoneInputType(PhoneInputType.GOOGLE_HINT)
.setOtpInputType(OtpInputType.AUTO_FILLED)
.setUserEventType(UserEventType.TRANSACTION)
.setMerchantId("1234567890")
.setAdditionalAttributes(additionalAttributes)
.build();
return updateOptions;
}
Future<void> initSign3Sdk() async {
var init = await Sign3Intelligence.isSdkInitialized();
var stopResult = await Sign3Intelligence.stop();
var id = await Sign3Intelligence.getSessionId();
setState(() {
initValue = init.toString();
stop = stopResult.toString();
sessionID = id;
});
}
Future<void> getIntelligence() async {
try {
var intelligence = await Sign3Intelligence.getIntelligence();
var id = await Sign3Intelligence.getSessionId();
setState(() {
if (Platform.isAndroid) {
jsonData = intelligence!.toJsonAndroid();
Log.i("TAG_GET_INTELLIGENCE_ANDROID", jsonData.toString());
} else if (Platform.isIOS) {
jsonData = intelligence!.toJsonIos();
Log.i("TAG_GET_INTELLIGENCE_iOS", jsonData.toString());
}
sessionID = id;
initValue = "true";
});
} catch (e) {
Log.i("TAG_GET_INTELLIGENCE_ERROR", e.toString());
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(e.toString()),
),
);
}
}
Future<void> updateOptions(UpdateOptions options) async {
await Sign3Intelligence.updateOptions(options);
}
}