fluent_adflow_widget 3.0.0 copy "fluent_adflow_widget: ^3.0.0" to clipboard
fluent_adflow_widget: ^3.0.0 copied to clipboard

Fluent AdFlow Widget

example/lib/main.dart

import 'package:fluent_adflow_widget/fluent_adflow_widget.dart';
import 'package:fluent_adflow_widget_example/leadManagerSlingSample.dart';
import 'package:flutter/material.dart';
import 'appConfig.dart';
import 'leadManagerSample.dart';
import 'popupAndInlineSample.dart';
import 'slideUpDrawerSample.dart';
import 'dualKeyPlacementsSample.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Sample Selector',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  bool leadManagerInitialized = false;
  bool dualKeyPlacementsInitialized = false;
  bool firstLoad = true;
  String apiKey = '';
  String referrer = '';
  void initializeWidget(String apiKeyValue, String referrerValue,
      {Function? onSuccess, Function(int, String)? onError}) {
    setState(() {
      apiKey = apiKeyValue;
      referrer = referrerValue;
      leadManagerInitialized = referrerValue.isEmpty;
      firstLoad = false;
      dualKeyPlacementsInitialized = false;
    });

    debugPrint("apiKey: $apiKeyValue");
    debugPrint("referrerValue: $referrerValue");
    FluentAdFlowWidget.init(
      apiKeyValue,
      referrerValue,
      (onSuccess as void Function()?) ??
          () {
            debugPrint("Initialization succeeded!");
          },
      onError ??
          (errorCode, errorMessage) {
            debugPrint("Initialization failed: $errorCode, $errorMessage");
          },
    );
  }

  void initMultiConfigWidget(
    List<Map<String, String?>> configs, {
    Function? onSuccess,
    Function(int, String)? onError,
  }) {
    setState(() {
      firstLoad = false;
      leadManagerInitialized = false;
      dualKeyPlacementsInitialized = true;
      apiKey = "Multi config";
      referrer = "Multi config";
    });

    debugPrint("initWithConfigs called with ${configs.length} configs");
    FluentAdFlowWidget.initWithConfigs(
      configs,
      (onSuccess as void Function()?) ??
          () {
            debugPrint("Initialization succeeded!");
          },
      onError ??
          (int errorCode, String errorMessage) {
            debugPrint("Initialization failed: $errorCode, $errorMessage");
          },
    );
  }

  String formatApiKey(String key) {
    if (key.length <= 10) return key;
    return '${key.substring(0, 5)}...${key.substring(key.length - 5)}';
  }

  // Add this helper to produce the post-init option widgets deterministically
  List<Widget> _postInitOptions(BuildContext context) {
    if (firstLoad) {
          return [];
    }

    if (dualKeyPlacementsInitialized) {
      return [
        ElevatedButton(
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => DualKeyPlacementsSample(
                  ad1Location: 'standardFlow',
                  ad2Location: 'frequencyFlow',
                  ad3Location: 'standardFlow',
                ),
              ),
            );
          },
          style: ElevatedButton.styleFrom(
              backgroundColor: Colors.teal, foregroundColor: Colors.white),
          child: const Text('Go to Dual Key Placements'),
        ),
        const SizedBox(height: 10),
      ];
    } else if (leadManagerInitialized) {
      return [
        ElevatedButton(
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => LeadManagerSample()),
            );
          },
          style: ElevatedButton.styleFrom(
              backgroundColor: Colors.purple, foregroundColor: Colors.white),
          child: const Text('Go to Lead Manager Sample'),
        ),
        const SizedBox(height: 10),
        ElevatedButton(
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => LeadManagerSlingSample()),
            );
          },
          style: ElevatedButton.styleFrom(
              backgroundColor: Colors.cyan, foregroundColor: Colors.white),
          child: const Text('Go to LM Sling Sample'),
        ),
      ];
    } else {
      return [
        ElevatedButton(
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => PopupAndInlineSample()),
            );
          },
          style: ElevatedButton.styleFrom(
              backgroundColor: Colors.pink, foregroundColor: Colors.white),
          child: const Text('Launch Popup and Inline Sample'),
        ),
        const SizedBox(height: 10),
        ElevatedButton(
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => SlideUpDrawerSample()),
            );
          },
          style: ElevatedButton.styleFrom(
              backgroundColor: Colors.cyan, foregroundColor: Colors.white),
          child: const Text('Launch Slide Up Drawer Sample'),
        ),
      ];
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Sample Selector')),
      body: Container(
        alignment: Alignment.topCenter, // Ensures top alignment
        padding: const EdgeInsets.all(20.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center, // Centers horizontally
          children: [
            const Text(
              'Flutter Sample App',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 20),
            Container(
              padding: const EdgeInsets.all(10),
              decoration: BoxDecoration(
                color: Colors.grey[200],
                borderRadius: BorderRadius.circular(10),
              ),
              child: Column(
                children: [
                  const Text(
                    'API KEY:',
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  Text(formatApiKey(apiKey)),
                  const SizedBox(height: 10),
                  const Text(
                    'REFERRER:',
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  Text(referrer),
                ],
              ),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                initializeWidget(
                    AppConfig.STANDARD_API_KEY, AppConfig.STANDARD_REFERRER);
              },
              style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.green, foregroundColor: Colors.white),
              child: const Text('Initialize Standard Adflow'),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                initializeWidget(AppConfig.FREQUENCY_CAPPING_API_KEY,
                    AppConfig.FREQUENCY_CAPPING_REFERRER);
              },
              style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.blue, foregroundColor: Colors.white),
              child: const Text('Initialize Frequency Capping'),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                initializeWidget(AppConfig.LEAD_MANAGER_API_KEY, '');
              },
              style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.orange,
                  foregroundColor: Colors.white),
              child: const Text('Initialize Lead Manager'),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                initMultiConfigWidget([
                  {
                    'apiKey': AppConfig.STANDARD_API_KEY,
                    'referrer': AppConfig.STANDARD_REFERRER,
                    'location': 'standardFlow'
                  },
                  {
                    'apiKey': AppConfig.FREQUENCY_CAPPING_API_KEY,
                    'referrer': AppConfig.FREQUENCY_CAPPING_REFERRER,
                    'location': 'frequencyFlow'
                  },
                ]);
              },
              style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.blue, foregroundColor: Colors.white),
              child: const Text('Initialize DualKeyPlacementsSample'),
            ),
            const SizedBox(height: 20),
            // deterministic single-source logic for post-init options
            ..._postInitOptions(context),
          ],
        ),
      ),
    );
  }
}
1
likes
130
points
208
downloads

Publisher

unverified uploader

Weekly Downloads

Fluent AdFlow Widget

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface, yaml

More

Packages that depend on fluent_adflow_widget

Packages that implement fluent_adflow_widget