-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
155 lines (138 loc) · 4.96 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import 'package:easy_ads_flutter/easy_ads_flutter.dart';
import 'package:easy_presentation/easy_presentation.dart';
import 'package:example/models/mock_data.dart';
import 'package:example/models/test_ad_id_manager.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyAds.instance.initialize(
const TestAdIdManager(),
fbiOSAdvertiserTrackingEnabled: true,
fbTestMode: true,
unityTestMode: true,
isAgeRestrictedUserForApplovin: false,
admobConfiguration: RequestConfiguration(
testDeviceIds: [], maxAdContentRating: MaxAdContentRating.pg),
adMobAdRequest:
const AdRequest(nonPersonalizedAds: false, keywords: <String>[]),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
EasyAds.instance.loadAd();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder<List<PresentationData>>(
/// Load markdown (.txt) files data
future: loadAllData(PresentationData.fromJsonList(jsonWithMarkdown)),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data == null) {
return const Text('Some error occur !!!');
}
return EasyPresentationApp(
leadingTitle: 'FF',
title: 'Data',
bgImage:
'https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=576&q=80',
presentationData: snapshot.data!,
onTapEvent: _handleEventActions,
placementBuilder: _addPlacements,
);
}
return const Center(child: CircularProgressIndicator());
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
/// Use this [EasyPresentationApp.launchApp()] to launch as a standalone app
EasyPresentationApp.launchApp(
context,
title: 'Data',
bgImage:
'https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=576&q=80',
leadingTitle: 'Mock',
presentationData: modelData,
onTapEvent: _handleEventActions,
);
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
/// you can add your own placement widget like this
Widget _addPlacements(BuildContext context, PresentationPlacement placement) {
switch (placement) {
case PresentationPlacement.presentationCategoryTop:
return const EasyBannerAd(adNetwork: AdNetwork.admob);
case PresentationPlacement.coverDetailBottom:
return Container(height: 50, width: double.infinity, color: Colors.red);
case PresentationPlacement.tabDetailBottom:
return Container(
height: 50, width: double.infinity, color: Colors.green);
case PresentationPlacement.youtubeDetailBottom:
return Container(
height: 50, width: double.infinity, color: Colors.orange);
default:
return const SizedBox();
}
}
/// You can handle every action performed by the user like this
void _handleEventActions(
BuildContext context, PresentationEventAction event) {
if (event == PresentationEventAction.cardTap) {
EasyAds.instance.showAd(AdUnitType.interstitial);
} else if (event == PresentationEventAction.backTap) {
printLog('Back Pressed');
} else if (event == PresentationEventAction.tabChanged) {
printLog('Tab Swiped');
}
}
void printLog(String str) {
if (kDebugMode) {
print(str);
}
}
/// Use this to load your markdown (.txt) files
static Future<List<PresentationData>> loadAllData(
List<PresentationData> data) async {
for (int i = 0; i < data.length; i++) {
final category = data[i];
if (category.detailText != null &&
category.detailText!.startsWith("assets/data/")) {
category.detailText = await rootBundle.loadString(category.detailText!);
}
if (category.subCategories != null) {
await loadAllData(category.subCategories!);
}
}
return data;
}
}