cmp_sdk_v3 2.9.0 copy "cmp_sdk_v3: ^2.9.0" to clipboard
cmp_sdk_v3: ^2.9.0 copied to clipboard

The CMP Plugin allows you to integrate Consent Management functionality.

example/lib/main.dart

import 'package:cmp_sdk_example/widgets/consent_layer_ui_config_card.dart';
import 'package:cmp_sdk_v3/consent_layer_ui_config.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'viewmodels/cmp_view_model.dart';
import 'views/config_section.dart';
import 'views/action_buttons.dart';
import 'views/status_section.dart';
import 'views/logs_section.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => CMPViewModel()),
      ],
      child: const MaterialApp(
        home: HomeScreen(),
      ),
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  HomeScreenState createState() => HomeScreenState();
}

class HomeScreenState extends State<HomeScreen> {
  @override
  void initState() {
    super.initState();
    // Calling initCMP() after the widget is initialized
    WidgetsBinding.instance.addPostFrameCallback((_) {
      Provider.of<CMPViewModel>(context, listen: false).initCMP();
    });
  }

  // Function to show the UI Config Card in a modal
  void _showConfigModal(BuildContext context) {
    final viewModel = Provider.of<CMPViewModel>(context, listen: false);

    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      builder: (context) {
        return Padding(
          padding: EdgeInsets.only(
            bottom: MediaQuery.of(context).viewInsets.bottom,
          ),
          child: FractionallySizedBox(
            heightFactor: 0.7, // Adjust the modal height if necessary
            child: ConsentLayerUIConfigCard(
              onConfigChanged: (ConsentLayerUIConfig config) {
                setState(() {});
              },
              onSubmit: (ConsentLayerUIConfig config) {
                viewModel.setWebViewConfig(config);
                Navigator.of(context).pop(); // Close the modal on submit
              },
            ),
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    Provider.of<CMPViewModel>(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text('CMP SDK V3 App'),
      ),
      body: const SingleChildScrollView(
        padding: EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ConfigSection(),
            SizedBox(height: 24.0),
            ActionButtons(),
            SizedBox(height: 24.0),
            StatusSection(),
            SizedBox(height: 24.0),
            LogsSection(),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => _showConfigModal(context), // Show the settings modal
        child: const Icon(Icons.settings), // Settings icon for the button
      ),
    );
  }
}
0
likes
160
pub points
0%
popularity

Publisher

unverified uploader

The CMP Plugin allows you to integrate Consent Management functionality.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on cmp_sdk_v3