fluent_adflow_widget 1.0.0-beta.5 copy "fluent_adflow_widget: ^1.0.0-beta.5" to clipboard
fluent_adflow_widget: ^1.0.0-beta.5 copied to clipboard

Fluent AdFlow Widget

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:fluent_adflow_widget/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),
      constraints: const BoxConstraints.expand(),
      child: Center(
        widthFactor: 0.8,
        child: Padding(
          padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 20),
          child: FluentAdFlowWidgetView(
            onAdShow: (isAdShown) {
              //for showing backdrop when ad loads
              setState(() {
                isDialogOpen = isAdShown;
              });
              //close dialogue when ad is hidden
              if (!isAdShown) {
                if (Navigator.canPop(context)) {
                  Navigator.of(context, rootNavigator: true).pop(context);
                }
              }
              //call onAdShow callback of parent widget
              if (widget.onAdShow != null) {
                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;
  //user details
  var userDetails = {
    "email": "jsmith@gmail.com",
    "firstname": "John",
    "lastname": "Smith",
    "orderId": "123abc456def",
    "transactionValue": "99.99",
    "zip": "11211",
  };

  @override
  void initState() {
    super.initState();
    FluentAdFlowWidget.init(
        "e8699957-af84-479d-af1e-dd95e800da77", "sdk_prod_test");
  }

  void onAdShown(bool isShown) {
    print("^^^^^^^^^ onAdShown ^^^^^^^^^" + (isShown ? "true" : "false"));
    setState(() {
      if (!isShown) showEmbededAd = false;
      showPopUpAd = false;
    });
  }

  @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')),
            ),
            //embedded ad view
            showEmbededAd
                ? FluentAdFlowWidgetView(
                    onAdShow: onAdShown,
                    params: userDetails,
                  )
                : Container(),
            Container(
              height: 50,
              color: Colors.amber[600],
              child: const Center(child: Text('Lower View')),
            ),
            ElevatedButton(
              onPressed: () => {
                //open ad view in popup dialog
                showDialog(
                    context: context,
                    barrierColor: Color(0x01000000),
                    builder: (context) =>
                        PopupModule(onAdShow: onAdShown, params: userDetails)),
              },
              child: const Text('Popup View'),
            ),

            ElevatedButton(
              onPressed: () => {
                setState(() {
                  showEmbededAd = true;
                })
              },
              child: const Text('Embedded View'),
            ),
          ]),
        ]));
  }
}
1
likes
0
points
41
downloads

Publisher

unverified uploader

Weekly Downloads

Fluent AdFlow Widget

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface, yaml

More

Packages that depend on fluent_adflow_widget