flutter_consent_flow 1.0.4
flutter_consent_flow: ^1.0.4 copied to clipboard
This library provides methods to identify the relevant regulatory framework based on the user's IP or location and request consent from the user.
import 'package:flutter/material.dart';
import 'package:flutter_consent_flow/flutter_consent_flow.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
FlutterConsentFlow.initialize(
httpReferer: 'YOUR_REFERER',
userAgent: 'YOUR_USER_AGENT',
enableLogs: true,
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Consent Flow',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: Builder(builder: (context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: FilledButton(
onPressed: () async {
final RegulatoryFramework? regulatoryFramework =
await FlutterConsentFlow.getRegulatoryFrameworkByIP(
apiKey: 'YOUR_API_KEY',
);
if (regulatoryFramework == null) return;
if (context.mounted) {
/// handle consent
final bool? hasConsent = await showDialog(
context: context,
builder: (_) => FlutterConsentDialog(
regulatoryFramework: regulatoryFramework,
appIcon: const AssetImage('YOUR_APP_ICON'),
appName: 'YOUR_APP_NAME',
privacyPolicyLink: 'YOUR_PRIVACY_POLICY_URL',
),
);
if (hasConsent ?? false) {
/// user has given consent
} else {
/// user
}
}
},
child: const Text('Check & Request'),
),
)
],
),
);
}),
);
}
}