flutter_conscent_plugin 0.4.0
flutter_conscent_plugin: ^0.4.0 copied to clipboard
This is a step by step guide for managing Conscent Plugin and its related subclasses.
example/lib/main.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_conscent_plugin/conscent_initializer.dart';
import 'package:flutter_conscent_plugin/conscent_methods.dart';
import 'package:flutter_conscent_plugin/datamodel/api_mode.dart';
import 'package:flutter_conscent_plugin/datamodel/getuser_detail.dart';
import 'package:flutter_conscent_plugin/extra.dart';
import 'package:flutter_conscent_plugin/web_view_login.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'paywall.dart';
ConscentInitializer? conscentInitializer;
void main() {
runApp(MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const MyApps(),
),
);
conscentInitializer =
ConscentInitializer("5f92a62013332e0f667794dc", ENVIRONMENTMODE.STAGE);
}
class MyApps extends StatefulWidget {
const MyApps({super.key});
// MyCustomForm createState() => MyCustomForm();
@override
State<MyApps> createState() => _MyCustomForm();
}
// ignore: must_be_immutable
class _MyCustomForm extends State<MyApps> {
final clientIdController = TextEditingController();
final contentIdController = TextEditingController();
final token = TextEditingController();
final phone = TextEditingController();
final email = TextEditingController();
late final WebViewController controller;
@override
void initState() {
super.initState();
controller = WebViewController();
}
@override
Widget build(BuildContext context) {
clientIdController.text = '5f92a62013332e0f667794dc';
contentIdController.text = 'Client-Story-Id-1';
token.text = '6436405cb0658c70abe7f2c5';
email.text = "";
phone.text = "9599540935";
GetUserDetail? getusermain;
return Scaffold(
appBar: AppBar(
title: const Text('Conscent setting ',
style: TextStyle(
color: Colors.white,
),
softWrap: true,
),
backgroundColor: Colors.blue,
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 16),
child: TextFormField(
controller: clientIdController,
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter your Client Id',
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 16),
child: TextFormField(
controller: contentIdController,
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter your Content Id',
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 16),
child: TextFormField(
controller: token,
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter login Token',
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 16),
child: TextFormField(
controller: phone,
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter phone number',
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 16),
child: TextFormField(
controller: email,
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter email ',
),
),
),
Column(
children: [
const SizedBox(
height: 50,
),
TextButton.icon(
// <-- TextButton
onPressed: () {
ConscentInitializer.setClientId(clientIdController.text);
ConscentInitializer.setContentId(contentIdController.text);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const MyAppff()),
);
},
icon: const Icon(
Icons.skip_next,
size: 24.0,
),
label: const Text('Next'),
),
TextButton.icon(
// <-- TextButton
onPressed: () {
ConscentInitializer.setContentId(contentIdController.text);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyAp(),
),
);
},
icon: const Icon(
Icons.mode,
size: 24.0,
),
label: const Text('Embedded Mode'),
),
TextButton.icon(
// <-- TextButton
// onPressed: () {
// print('user');
// getUser();
// },
icon: const Icon(
Icons.skip_next,
size: 24.0,
),
// label: Text('User Details'),
label: const Text(
'User Detail',
),
onPressed: () async {
const CircularProgressIndicator();
getusermain = await ConscentMethods().getUser();
print('${getusermain?.toJson()}');
showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('User Detail'),
content: Text(
'${getusermain?.toJson()}',
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
}),
TextButton.icon(
// <-- TextButton
onPressed: () async {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => WebViewLogin( token: token.text, phone: phone.text, email: email.text , controller: controller,),
)).then((value) {
if (value != null) {
dynamic response = value;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('$response'),
));
}
});
},
icon: const Icon(
Icons.login,
size: 24.0,
),
label: const Text('Login'),
),
TextButton.icon(
// <-- TextButton
onPressed: () async {
String? logout = await ConscentMethods().userLogOut();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('${logout}'),
));
// logOut();
},
icon: const Icon(
Icons.logout,
size: 24.0,
),
label: const Text('Logout'),
),
],
)
],
),
),
);
}
}