flutter_access 1.0.0 copy "flutter_access: ^1.0.0" to clipboard
flutter_access: ^1.0.0 copied to clipboard

Poool's flutter package allows to make a bridge between flutter applications and Poool Access solution accross common platforms (IOS & Android).

example/lib/main.dart

// ignore_for_file: avoid_print

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_access/flutter_access.dart';

void main() => runApp(const TheSpender());

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

  @override
  State<TheSpender> createState() => _TheSpender();
}

class _TheSpender extends State<TheSpender> {
  final mediaColor = const Color(0xffE3120B);

  @override
  Widget build(BuildContext context) {
    String appId =
        "Qz9V02LNSO78aGfJEuAKNGTNmC8vbzmW6nEW8USQjlQGUcWbmWCtIT31mpWbVEG0";

    return MaterialApp(
      title: 'Flutter Access',
      home: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: const Text('The Spender - Premium article'),
          backgroundColor: mediaColor,
        ),
        body: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              MultiProvider(
                providers: [
                  ChangeNotifierProvider(
                      create: (ref) => AccessProvider(
                            appId: appId,
                            debug: true,
                          )),
                ],
                child: const Content(),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

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

  @override
  State<Content> createState() => _Content();
}

class _Content extends State<Content> {
  @override
  Widget build(BuildContext context) {
    const mediaColor = Color(0xffE3120B);
    const appId =
        "Qz9V02LNSO78aGfJEuAKNGTNmC8vbzmW6nEW8USQjlQGUcWbmWCtIT31mpWbVEG0";

    const config = {
      "debug": true,
      // "force_widget": 'gift',
      "cookies_enabled": true,
      // "login_button_enabled": false,
      "alternative_enabled": true,
      // "subscription_button_enabled": false,
    };
    const texts = {
      "form_title": "Hello form {test_variable}",
    };
    const variables = {
      "test_variable": "Any variable test",
    };
    const styles = {
      "skin_color": "#FF0000",
    };
    var events = {
      "onDismissBottomSheet": (args) {
        print("User closed the bottom sheet");
      },
      "onError": (args) {
        print("onError event triggered with args: $args");
      },
      "onLock": (args) {
        print("onLock event called with args: $args");
      },
      "onReady": (args) {
        print("onReady with args: $args");
      },
      "onLoginClick": (args) {
        print("OnLoginClick with args: $args");
      },
      "onSubscribeClick": (args) {
        print("onSubscribeClick with args: $args");
      },
      "onPaywallSeen": (args) {
        print("onPaywallSeen custom event called with args: $args");
      },
      "onRelease": (args) {
        print("onRelease custom event called with args: $args");
      },
      "onRegister": (args) {
        print("Testing async onRegister with args: $args");

        Future<List?> waitTask() async {
          await Future.delayed(const Duration(seconds: 3));
          var fieldValue = args["event"]["email"];
          if (fieldValue == 'fail@poool.fr') {
            return [
              {"fieldKey": "email", "message": "This email is not allowed"}
            ];
          } else {
            return null;
          }
        }

        return waitTask();
      },
      "onFormSubmit": (args) {
        print("Testing async onFormSubmit with args: $args");

        Future<List?> waitTask() async {
          await Future.delayed(const Duration(seconds: 3));
          var fieldValue = args["event"]["fields"]["the_variable"];
          if (fieldValue == 'fail') {
            return [
              {
                'fieldKey': 'the_variable',
                'message': 'This text is not allowed'
              }
            ];
          }

          return null;
        }

        return waitTask();
      },
    };

    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text(
              'A different dystopia: July 2030',
              style: TextStyle(
                color: mediaColor,
                fontWeight: FontWeight.w600,
                fontSize: 16,
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 8),
              child: const Text(
                'What if robots don’t take all the jobs?',
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 30,
                ),
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 16),
              child: const Text(
                'The real danger to future prosperity could be too few robots, not too many. An imagined scenario from 2030',
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 18,
                ),
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 20),
              child:
                  Image.network('https://wallpapercave.com/wp/wp4507667.jpg'),
            ),
            Container(
              margin: const EdgeInsets.only(top: 20, bottom: 20),
              child: const Text(
                'It is hard to believe now, but a little more than a decade ago people were seriously worried about robots taking all the jobs. Back in 2018 the chief economist of the Bank of England, Andy Haldane, gave a warning that “large swathes” of the population would become “technologically unemployed”.',
                style: TextStyle(
                  fontSize: 16,
                ),
              ),
            ),
            // AccessBottomSheet(
            //   appId: appId,
            //   config: config,
            //   texts: texts,
            //   styles: styles,
            //   events: events,
            //   variables: variables,
            //   releaseOnError: false,
            // ),
            Container(
              margin: const EdgeInsets.only(top: 16),
              decoration: BoxDecoration(
                  border: Border.all(
                      color: const Color.fromARGB(255, 249, 64, 58))),
              child: AccessWrapper(
                appId: appId,
                children: [
                  const SnippetContent(),
                  const RestrictedContent(child: PremiumContent()),
                  Paywall(
                    pageType: 'premium',
                    config: config,
                    texts: texts,
                    styles: styles,
                    events: events,
                    variables: variables,
                    releaseOnError: false,
                    customViewLoader: const CircularProgressIndicator(
                      backgroundColor: Color.fromARGB(255, 255, 100, 75),
                    ),
                  ),
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 20, bottom: 20),
              child: const Text(
                'It is hard to believe now, but a little more than a decade ago people were seriously worried about robots taking all the jobs. Back in 2018 the chief economist of the Bank of England, Andy Haldane, gave a warning that “large swathes” of the population would become “technologically unemployed”.',
                style: TextStyle(
                  fontSize: 16,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Snippet(
      child: Container(
        margin: const EdgeInsets.only(top: 20, bottom: 20),
        child: const Column(children: [
          Text('Snippet', style: TextStyle(fontSize: 12)),
          Text(
            'It is hard to believe now, but a little more than a decade ago people were seriously worried about robots taking all the jobs. Back in 2018 the chief economist of the Bank of England, Andy Haldane, gave a warning that “large swathes” of the population would become “technologically unemployed”.',
            style: TextStyle(fontSize: 16),
          ),
        ]),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const Text('Restricted content', style: TextStyle(fontSize: 12)),
        const Text(
          'It is hard to believe now, but a little more than a decade ago people were seriously worried about robots taking all the jobs. Back in 2018 the chief economist of the Bank of England, Andy Haldane, gave a warning that “large swathes” of the population would become “technologically unemployed”.',
          style: TextStyle(
            fontSize: 16,
          ),
        ),
        Container(
          margin: const EdgeInsets.only(top: 20),
          child: const Text(
            'It is hard to believe now, but a little more than a decade ago people were seriously worried about robots taking all the jobs. Back in 2018 the chief economist of the Bank of England, Andy Haldane, gave a warning that “large swathes” of the population would become “technologically unemployed”.',
            style: TextStyle(
              fontSize: 16,
            ),
          ),
        ),
        Container(
          margin: const EdgeInsets.only(top: 20),
          child: const Text(
            'It is hard to believe now, but a little more than a decade ago people were seriously worried about robots taking all the jobs. Back in 2018 the chief economist of the Bank of England, Andy Haldane, gave a warning that “large swathes” of the population would become “technologically unemployed”.',
            style: TextStyle(
              fontSize: 16,
            ),
          ),
        ),
      ],
    );
  }
}
1
likes
40
points
25
downloads

Publisher

verified publisherpoool.tech

Weekly Downloads

Poool's flutter package allows to make a bridge between flutter applications and Poool Access solution accross common platforms (IOS & Android).

Repository (GitHub)
View/report issues

Topics

#poool #paywall #content #access #registration

Documentation

Documentation

License

MIT (license)

Dependencies

flutter, provider

More

Packages that depend on flutter_access