credify_collection_sms_sdk 1.3.0 credify_collection_sms_sdk: ^1.3.0 copied to clipboard
Flutter plugin for Credify Collection SDK that only collects SMS messages.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:credify_collection_sdk/credify_collection.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _credifyPlugin = CredifyCollection();
String collectedData = '';
bool loading = false;
@override
void initState() {
super.initState();
}
Future<void> collectData() async {
setState(() {
loading = true;
});
const encoder = JsonEncoder.withIndent(' ');
try {
dynamic initializeResult = await _credifyPlugin.initialize(
"<Place your application token here>");
await _credifyPlugin.setUserIdentifier("flutterSampleUser01");
dynamic data = await _credifyPlugin.collectData();
final object = json.decode(data);
final formattedJSON = encoder.convert(object);
setState(() {
collectedData = formattedJSON;
loading = false;
});
} on PlatformException catch (error) {
setState(() {
collectedData = encoder.convert(error);
loading = false;
});
} catch (error) {
collectedData = encoder.convert(error);
loading = false;
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Credify Plugin example app'),
),
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () => {_credifyPlugin.requestPermissions()},
child: Text("grant permissions")),
TextButton(
onPressed: () async => {collectData()},
child: Text("Collect Data"))
],
),
Expanded(
flex: 1,
child: loading
? const Center(child: CircularProgressIndicator())
: SingleChildScrollView(
scrollDirection: Axis.vertical, //.horizontal
child: Text(
collectedData,
style: const TextStyle(
fontSize: 16.0,
color: Colors.black,
),
),
))
],
)),
);
}
}