sdk_core_flutter 4.7.0
sdk_core_flutter: ^4.7.0 copied to clipboard
A plugin to integrate the Au10tix core module into other flutter feature plugins.
example/lib/main.dart
// ignore_for_file: use_key_in_widget_constructors
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sdk_core_flutter/sdk_core_flutter.dart';
import 'package:sdk_core_flutter_example/constants.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Au10tix Flutter Core Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
static const String _authToken = workflowResponse;
Future<void> _prepareSDK(BuildContext context) async {
try {
final result = await Au10tix.init(_authToken);
if (result.containsKey("init")) {
if (kDebugMode) {
print('${result["init"]}');
}
_showToast(context, result["init"].toString(), Colors.green);
}
} on PlatformException catch (error) {
_showToast(context, error.message!, Colors.red);
} catch (error) {}
}
Future<void> _destroy(BuildContext context) async {
try {
await Au10tix.destroy();
_showToast(context, 'SDK destroyed', Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
Future<void> _isOfflineMode(BuildContext context) async {
try {
final result = await Au10tix.isOfflineMode();
_showToast(context, 'isOffline: ' + result.toString(), Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
Future<void> _isPrepared(BuildContext context) async {
try {
final result = await Au10tix.isPrepared();
_showToast(context, 'isPrepared: ' + result.toString(), Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
Future<void> _clearCache(BuildContext context) async {
try {
await Au10tix.clearCache();
_showToast(context, 'Cache cleared', Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
Future<void> _clearDynamicAssetsCache(BuildContext context) async {
try {
await Au10tix.clearDynamicAssetsCache();
_showToast(context, 'Dynamic assets cache cleared', Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
Future<void> _getSessionId(BuildContext context) async {
try {
final result = await Au10tix.getSessionId();
_showToast(context, 'SessionId: ' + (result ?? 'null'), Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
Future<void> _getNativeSdkVersion(BuildContext context) async {
try {
final result = await Au10tix.getNativeSdkVersion();
_showToast(context, 'Native SDK Version: ' + (result ?? 'null'), Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
Future<void> _analyzePotentialRisks(BuildContext context) async {
try {
final result = await Au10tix.analyzePotentialRisks();
var risks = result.join(', ');
if (risks.isEmpty) {
risks = 'No risks detected';
}
_showToast(context, 'Potential Risks: ' + risks, Colors.green);
} catch (error) {
_showToast(context, error.toString(), Colors.red);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin core example app'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => _prepareSDK(context),
child: const Text("Prepare SDK"),
),
ElevatedButton(
onPressed: () => _isPrepared(context),
child: const Text("Is Prepared"),
),
ElevatedButton(
onPressed: () => _getSessionId(context),
child: const Text("Get Session Id"),
),
ElevatedButton(
onPressed: () => _getNativeSdkVersion(context),
child: const Text("Get Native SDK Version"),
),
ElevatedButton(
onPressed: () => _clearCache(context),
child: const Text("Clear Cache"),
),
ElevatedButton(
onPressed: () => _clearDynamicAssetsCache(context),
child: const Text("Clear Dynamic Assets Cache"),
),
ElevatedButton(
onPressed: () => _destroy(context),
child: const Text("Destroy SDK Instance"),
),
ElevatedButton(
onPressed: () => _isOfflineMode(context),
child: const Text("Is Offline Mode"),
),
ElevatedButton(
onPressed: () => _analyzePotentialRisks(context),
child: const Text("Analyze Potential Risks"),
),
],
),
),
),
);
}
void _showToast(BuildContext context, String message, Color bgColor) {
final scaffold = ScaffoldMessenger.of(context);
scaffold.showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: bgColor,
),
);
}
}