go_trust_mobile_sdk 1.0.3
go_trust_mobile_sdk: ^1.0.3 copied to clipboard
A Flutter mobile SDK for GoTrust consent and preference management.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:go_trust_mobile_sdk/features/consent_form/services/go_trust_sdk_helper.dart';
import 'package:go_trust_mobile_sdk/features/consent_form/consent_form_page.dart';
import 'package:go_trust_mobile_sdk/features/consent_preferences/widgets/login_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'GoTrust SDK Sample',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
useMaterial3: true,
),
home: const GoTrustSamplePage(),
);
}
}
class GoTrustSamplePage extends StatefulWidget {
const GoTrustSamplePage({super.key});
@override
State<GoTrustSamplePage> createState() => _GoTrustSamplePageState();
}
class _GoTrustSamplePageState extends State<GoTrustSamplePage> {
static const String _baseUrl = 'https://preprod.gotrust.tech';
static const String _sourceId =
'21U1hxuqMsVkIs8mRWnB6RAfr_N84pUI_D0qRIXVRcgL6w==';
static const String _customerId =
'4C3_opTopeRH5ScJzPvjSJbg_PW6LzxzMJoV1eSes7Y=';
static const String _preferenceFormId =
'AJfzcSYTaSfAN6xwuy2q3nbuJCtLkbMWQiB3xz0s';
static const String _token = "ed-tkQZQQtCVYBYRdDzlbzvqDAVCy9A4c04Htb57jQDDfXv1lZgbrypHNQd0Bq3B0YHVObcdOD_zuBf3p0o=";
final TextEditingController _identityController =
TextEditingController(text: 'pratyush@appvintech.com');
@override
void dispose() {
_identityController.dispose();
super.dispose();
}
Future<bool> _shouldOpenConsentForm(String subjectIdentity) async {
return GoTrustSdkHelper.showConsentForm(
_sourceId,
subjectIdentity,
_baseUrl,
);
}
Future<void> _openConsentForm() async {
final identity = _identityController.text.trim();
if (identity.isEmpty) {
_showMessage('Please enter email or phone first.');
return;
}
final shouldOpen = await _shouldOpenConsentForm(identity);
if (!shouldOpen) {
_showMessage('Consent already exists. Consent form is not required.');
return;
}
await Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => ConsentFormPage(
sourceId: _sourceId,
// customerId: _customerId,
initialSubjectValue: identity,
additionalParams: const <String, dynamic>{},
baseUrl: _baseUrl,
),
),
);
}
Future<void> _openPreferenceCenter() async {
final identity = _identityController.text.trim();
if (identity.isEmpty) {
_showMessage('Please enter email or phone first.');
return;
}
await Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => LoginPage(
pfToken: _token,
// customerId: _customerId,
// preferenceFormId: _preferenceFormId,
consentId: _sourceId,
emailOrPhone: identity,
additionalParams: const <String, dynamic>{},
baseUrl: _baseUrl,
),
),
);
}
void _showMessage(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('GoTrust Flutter Sample'),
),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Open Consent Form and Preference Center',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
const SizedBox(height: 12),
TextField(
controller: _identityController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Email or Phone',
),
),
const SizedBox(height: 8),
const Text(
'Configured with your shared source/customer/pref-center IDs.',
style: TextStyle(fontSize: 12, color: Colors.black54),
),
const SizedBox(height: 16),
FilledButton(
onPressed: _openConsentForm,
child: const Text('Open Consent Form'),
),
const SizedBox(height: 12),
OutlinedButton(
onPressed: _openPreferenceCenter,
child: const Text('Open Preference Center'),
),
],
),
),
);
}
}