fluent_adflow_widget 0.0.1-dev.2 copy "fluent_adflow_widget: ^0.0.1-dev.2" to clipboard
fluent_adflow_widget: ^0.0.1-dev.2 copied to clipboard

Fluent AdFlow Widget SDK for Flutter

example/lib/main.dart

import 'package:flutter/material.dart';
// import 'package:fluent_flutter_plugin/fluent_flutter_plugin.dart';
import 'package:fluent_flutter_plugin/FluentAdFlowWidget.dart';

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


class PopupModule extends StatefulWidget {
  final Function(bool)? onAdShow;
  Map<String, String>? params;
  PopupModule({this.onAdShow, this.params});
  @override
  State<PopupModule> createState() => PopupModuleState();
}

class PopupModuleState extends State<PopupModule> {
  bool isDialogOpen = false;
  @override
  Widget build(BuildContext context) {
    return Container(
      color: isDialogOpen ? const Color.fromARGB(100, 0, 0, 0) : const Color(0x01000000),
      // color: const Color.fromARGB(100, 0, 0, 0),
      constraints: const BoxConstraints.expand(),
      child: Center(
        widthFactor: 0.8,
        child: Padding(
          padding: const EdgeInsets.symmetric(
              vertical: 0, horizontal: 20),
          child: FluentAdFlowWidgetView(
            onAdShow: (isAdShown)
            {
              print('***************************************1');
              setState(() {
                isDialogOpen = isAdShown;
              });
              print('***************************************2');
              if(widget.onAdShow != null) {
                print('***************************************3');
                widget.onAdShow!(isAdShown);
              }
            },
            params: widget.params,
          ),
        ),
      ),
    );
  }
}


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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AdFlow Flutter App',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // late Widget content;
  bool isDialogOpen = false;
  bool showEmbededAd = false;
  bool showPopUpAd = false;

  @override
  void initState() {
    super.initState();
    // content = FluentAdFlowWidgetView(onAdShow: onAdShow);
    // WidgetsBinding.instance.addPostFrameCallback((_) {
    //   Future.delayed(Duration(seconds: 3), () {
    FluentAdFlowWidget.init(
        "e8699957-af84-479d-af1e-dd95e800da77", "sdk_prod_test");
    // });
    // });
    // AdFlowWidget.init("e8699957-af84-479d-af1e-dd95e800da77", "sdk_prod_test");
  }

  void onAdShown(bool isShown) {
    setState(() {
      if(!isShown)
        showEmbededAd = false;
        showPopUpAd = false;
    });
    if (isShown) {
      print(' ');
      print('***************************************');
      print('********  The Ad is displayed. ********');
      print('***************************************');
      print(' ');
    } else {
      print(' ');
      print('***************************************');
      print('***********  No Ad to show. ***********');
      print('***************************************');
      print(' ');
      if (Navigator.canPop(context)) {
        Navigator.pop(context);
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body:Stack(
        children:[
        ListView(children: [
          Container(
            height: 50,
            color: Colors.amber[600],
            child: const Center(child: Text('Upper View')),
          ),
          showEmbededAd ? FluentAdFlowWidgetView(
            onAdShow: onAdShown,
            params: {"email": "jsmith@gmail.com"},
          ) : Container(),
          Container(
            height: 50,
            color: Colors.amber[600],
            child: const Center(child: Text('Lower View')),
          ),
          ElevatedButton(
            onPressed: () =>
            {
              showDialog(
                context: context,
                barrierColor: Color(0x01000000),
                builder: (context) =>
                  PopupModule(onAdShow: (isAdShown)
                  {
                    if(!isAdShown) {
                      Navigator.pop(context);
                    }
                    onAdShown(isAdShown);
                  }, params: const {"email": "jsmith@gmail.com"})
              ),
            },
            child: const Text('Popup View'),
          ),

          ElevatedButton(
            onPressed: () => {
              setState(() {
                showEmbededAd = true;
              })
            },
            child: const Text('Embeded View'),
          ),
          //FluentAdFlowWidgetView(onAdShow: onAdShow),
        ]),
          // showPopUpAd ? const Positioned.fill(
          //     child: Center(child: const content,)
          // ): Container()
        ])
    );
  }
}
1
likes
0
points
41
downloads

Publisher

unverified uploader

Weekly Downloads

Fluent AdFlow Widget SDK for Flutter

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on fluent_adflow_widget