silent 0.0.2
silent: ^0.0.2 copied to clipboard
Silent SDK is a technical solution for collecting some end user and mobile device data in the host application with minimal influence on the user experience
example/lib/main.dart
import 'package:customized/customized.dart';
import 'package:flutter/material.dart';
import 'package:silent/silent_plugin.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Silent.initialize(
packageName: 'packageName',
appId: 'appId',
appSecret: 'appSecret');
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Silent SDK',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Silent SDK'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _isValidated = false;
bool _isTelephonyRequested = false;
bool _isLocationRequested = false;
void onRequestLocation() async {
var result = await Silent.requestLocation();
setState(() => _isLocationRequested = result);
print('accepted: $result');
}
void onRequestTelephony() async {
var result = await Silent.requestTelephony();
setState(() => _isTelephonyRequested = result);
print('accepted: $result');
}
void onCapture() async {
var uid = '3593569363956739';
var loadId = DateTime.now().toIso8601String();
var result = await Silent.capture(uid: uid, loadId: loadId);
print('captured: $result');
}
void onInitialize() async {
await Future.delayed(const Duration(seconds: 2));
var isValidated = await Silent.isValidated();
setState(() => _isValidated = isValidated);
}
Widget _itemInfoBody({required String value, required String label}) {
return Container(
alignment: Alignment.centerLeft,
child: Text.rich(TextSpan(children: [
TextSpan(
text: label,
style:
const TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0)),
TextSpan(text: ': ', style: const TextStyle(fontSize: 18.0)),
TextSpan(text: value, style: const TextStyle(fontSize: 18.0))
])),
);
}
@override
void initState() {
super.initState();
onInitialize();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
padding: EdgeInsets.all(18.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_itemInfoBody(
label: 'Silent SDK initialized?', value: '$_isValidated'),
const SizedBox(
height: 8.0,
),
_itemInfoBody(
label: 'Location Requested?', value: '$_isLocationRequested'),
const SizedBox(
height: 8.0,
),
_itemInfoBody(
label: 'Telephony Requested?',
value: '$_isTelephonyRequested'),
const SizedBox(
height: 50.0,
),
DefaultButton(
text: 'Request Location',
onPressed: onRequestLocation,
),
const SizedBox(
height: 16.0,
),
DefaultButton(
text: 'Request Telephony',
onPressed: onRequestTelephony,
),
const SizedBox(
height: 16.0,
),
DefaultButton(
text: 'Capture Data',
onPressed: onCapture,
),
],
),
),
),
);
}
}