fluent_adflow_widget 2.0.2
fluent_adflow_widget: ^2.0.2 copied to clipboard
Fluent AdFlow Widget
example/lib/main.dart
import 'package:fluent_adflow_widget/FluentAdFlowWidget.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';
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 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;
});
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");
},
);
}
String formatApiKey(String key) {
if (key.length <= 10) return key;
return '${key.substring(0, 5)}...${key.substring(key.length - 5)}';
}
@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: 20),
if (!firstLoad)
leadManagerInitialized
? Column(children: [
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'),
)
])
: Column(
children: [
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'),
),
],
),
],
),
),
);
}
}