flutter_conscent_plugin 0.4.2 copy "flutter_conscent_plugin: ^0.4.2" to clipboard
flutter_conscent_plugin: ^0.4.2 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/foundation.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_default.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

import 'paywall.dart';

ConscentInitializer? conscentInitializer;
Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (!kIsWeb &&
      kDebugMode &&
      defaultTargetPlatform == TargetPlatform.android) {
    await InAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode);
  }

  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();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    clientIdController.text = '5f92a62013332e0f667794dc';
    contentIdController.text = 'Client-Story-Id-1';
    token.text = '644291cf2ef1470d7c2a324c';
    email.text = "roshan@conscent.ai";
    phone.text = "";

    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()}');
                      if (context.mounted) {
                        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 {
                    String redirectUrl = await ConscentMethods()
                        .prepareAutoLoginUrl(
                            [(token.text), (phone.text), (email.text)]);
                    if (context.mounted) {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) =>
                                WebViewDefaultApp(redirectUrl: redirectUrl)),
                      ).then((value) {
                        print("response $value");
                        if (value != null) {
                          ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                            content: Text('$value'),
                          ));
                        }
                      });
                    }
                  },
                  icon: const Icon(
                    Icons.login,
                    size: 24.0,
                  ),
                  label: const Text('Login'),
                ),
                TextButton.icon(
                  // <-- TextButton
                  onPressed: () async {
                    String? logout = await ConscentMethods().userLogOut();
                    if (context.mounted) {
                      ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                        content: Text('$logout'),
                      ));
                    }
                    // logOut();
                  },
                  icon: const Icon(
                    Icons.logout,
                    size: 24.0,
                  ),
                  label: const Text('Logout'),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}