flutter_conscent_plugin 0.3.7 copy "flutter_conscent_plugin: ^0.3.7" to clipboard
flutter_conscent_plugin: ^0.3.7 copied to clipboard

This is a step by step guide for managing Conscent Plugin and its related subclasses.

example/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 'paywall.dart';

ConscentInitializer? conscentInitializer;
void main() {
  runApp(const MyApps());

  conscentInitializer =
      ConscentInitializer("5f92a62013332e0f667794dc", ENVIRONMENTMODE.STAGE);
}

class MyApps extends StatelessWidget {
  const MyApps({super.key});

  MyCustomForm createState() => MyCustomForm();

  @override
  Widget build(BuildContext context) {
    const appTitle = 'Setting';

    return MaterialApp(
      title: appTitle,
      home: Scaffold(
        appBar: AppBar(
          title: const Text(appTitle),
          backgroundColor: Colors.blue,
        ),
        body: MyCustomForm(),
      ),
    );
  }
}

// ignore: must_be_immutable
class MyCustomForm extends StatelessWidget {
  MyCustomForm({super.key});

  final clientIdController = TextEditingController();
  final contentIdController = TextEditingController();
  final token = TextEditingController();
  final phone = TextEditingController();
  final email = TextEditingController();

  @override
  Widget build(BuildContext context) {
    clientIdController.text = '';
    contentIdController.text = '';
    token.text = '';
    email.text = "";

    GetUserDetail? getusermain;

    return 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',
                    style: TextStyle(
                      color: Colors.blue,
                    ),
                  ),
                  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 ),
                      )).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'),
              ),
            ],
          )
        ],
      ),
    );
  }
}