flet-ads 0.1.0.dev2__py3-none-any.whl → 0.2.0.dev37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flet-ads might be problematic. Click here for more details.
- flet_ads/__init__.py +9 -9
- flet_ads/banner_ad.py +29 -0
- flet_ads/base_ad.py +65 -172
- flet_ads/interstitial_ad.py +21 -0
- flet_ads/native_ad.py +32 -0
- flet_ads/types.py +129 -0
- flet_ads-0.2.0.dev37.dist-info/METADATA +66 -0
- flet_ads-0.2.0.dev37.dist-info/RECORD +11 -0
- {flet_ads-0.1.0.dev2.dist-info → flet_ads-0.2.0.dev37.dist-info}/WHEEL +1 -1
- {flutter/flet_ads → flet_ads-0.2.0.dev37.dist-info/licenses}/LICENSE +1 -1
- {flet_ads-0.1.0.dev2.dist-info → flet_ads-0.2.0.dev37.dist-info}/top_level.txt +0 -1
- flet_ads/banner.py +0 -110
- flet_ads/interstitial.py +0 -111
- flet_ads/native.py +0 -171
- flet_ads-0.1.0.dev2.dist-info/METADATA +0 -97
- flet_ads-0.1.0.dev2.dist-info/RECORD +0 -21
- flutter/flet_ads/CHANGELOG.md +0 -3
- flutter/flet_ads/README.md +0 -3
- flutter/flet_ads/analysis_options.yaml +0 -4
- flutter/flet_ads/lib/flet_ads.dart +0 -3
- flutter/flet_ads/lib/src/banner.dart +0 -96
- flutter/flet_ads/lib/src/create_control.dart +0 -29
- flutter/flet_ads/lib/src/interstitial.dart +0 -83
- flutter/flet_ads/lib/src/native.dart +0 -153
- flutter/flet_ads/lib/utils/native.dart +0 -69
- flutter/flet_ads/pubspec.lock +0 -759
- flutter/flet_ads/pubspec.yaml +0 -18
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import 'dart:convert';
|
|
2
|
-
|
|
3
|
-
import 'package:flet/flet.dart';
|
|
4
|
-
import 'package:flutter/material.dart';
|
|
5
|
-
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
|
6
|
-
|
|
7
|
-
import '../utils/native.dart';
|
|
8
|
-
|
|
9
|
-
class NativeAdControl extends StatefulWidget {
|
|
10
|
-
final Control? parent;
|
|
11
|
-
final Control control;
|
|
12
|
-
final FletControlBackend backend;
|
|
13
|
-
|
|
14
|
-
const NativeAdControl(
|
|
15
|
-
{super.key,
|
|
16
|
-
required this.parent,
|
|
17
|
-
required this.control,
|
|
18
|
-
required this.backend});
|
|
19
|
-
|
|
20
|
-
@override
|
|
21
|
-
State<NativeAdControl> createState() => _NativeAdControlState();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
class _NativeAdControlState extends State<NativeAdControl> with FletStoreMixin {
|
|
25
|
-
bool _isLoaded = false;
|
|
26
|
-
|
|
27
|
-
void loadAd() {
|
|
28
|
-
NativeAd(
|
|
29
|
-
adUnitId: widget.control.attrString(
|
|
30
|
-
"unitId", 'ca-app-pub-3940256099942544/2247696110')!,
|
|
31
|
-
listener: NativeAdListener(
|
|
32
|
-
onAdLoaded: (ad) {
|
|
33
|
-
debugPrint('$NativeAd loaded.');
|
|
34
|
-
widget.backend.triggerControlEvent(widget.control.id, "load");
|
|
35
|
-
setState(() {
|
|
36
|
-
_isLoaded = true;
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
onAdFailedToLoad: (ad, error) {
|
|
40
|
-
widget.backend.triggerControlEvent(
|
|
41
|
-
widget.control.id, "error", error.toString());
|
|
42
|
-
// Dispose the ad here to free resources.
|
|
43
|
-
debugPrint('$NativeAd failedToLoad: $error');
|
|
44
|
-
ad.dispose();
|
|
45
|
-
},
|
|
46
|
-
onAdClicked: (ad) {
|
|
47
|
-
widget.backend.triggerControlEvent(widget.control.id, "click");
|
|
48
|
-
},
|
|
49
|
-
onAdImpression: (ad) {
|
|
50
|
-
widget.backend
|
|
51
|
-
.triggerControlEvent(widget.control.id, "impression");
|
|
52
|
-
},
|
|
53
|
-
onAdClosed: (ad) {
|
|
54
|
-
widget.backend.triggerControlEvent(widget.control.id, "close");
|
|
55
|
-
},
|
|
56
|
-
onAdOpened: (ad) {
|
|
57
|
-
widget.backend.triggerControlEvent(widget.control.id, "open");
|
|
58
|
-
},
|
|
59
|
-
onAdWillDismissScreen: (ad) {
|
|
60
|
-
widget.backend
|
|
61
|
-
.triggerControlEvent(widget.control.id, "willDismiss");
|
|
62
|
-
},
|
|
63
|
-
onPaidEvent: (ad, valueMicros, precision, currencyCode) {
|
|
64
|
-
widget.backend.triggerControlEvent(
|
|
65
|
-
widget.control.id,
|
|
66
|
-
"paidEvent",
|
|
67
|
-
jsonEncode({
|
|
68
|
-
"value_micros": valueMicros,
|
|
69
|
-
"precision": precision,
|
|
70
|
-
"currency_code": currencyCode
|
|
71
|
-
}));
|
|
72
|
-
},
|
|
73
|
-
),
|
|
74
|
-
request: const AdRequest(),
|
|
75
|
-
nativeTemplateStyle: parseNativeTemplateStyle(
|
|
76
|
-
Theme.of(context), widget.control, "nativeTemplateStyle"))
|
|
77
|
-
.load();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@override
|
|
81
|
-
Widget build(BuildContext context) {
|
|
82
|
-
debugPrint(
|
|
83
|
-
"NativeAd build: ${widget.control.id} (${widget.control.hashCode})");
|
|
84
|
-
return withPagePlatform((context, platform) {
|
|
85
|
-
final testAdUnitId = platform == TargetPlatform.iOS
|
|
86
|
-
? 'ca-app-pub-3940256099942544/3986624511'
|
|
87
|
-
: 'ca-app-pub-3940256099942544/2247696110';
|
|
88
|
-
var factoryId = widget.control.attrString("factoryId");
|
|
89
|
-
var nativeTemplateStyle = parseNativeTemplateStyle(
|
|
90
|
-
Theme.of(context), widget.control, "templateStyle");
|
|
91
|
-
if (factoryId == null && nativeTemplateStyle == null) {
|
|
92
|
-
return const ErrorControl(
|
|
93
|
-
"factory_id or native_template_style is required");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
NativeAd nativeAd = NativeAd(
|
|
97
|
-
adUnitId: widget.control.attrString("unitId", testAdUnitId)!,
|
|
98
|
-
factoryId: factoryId,
|
|
99
|
-
listener: NativeAdListener(
|
|
100
|
-
onAdLoaded: (ad) {
|
|
101
|
-
debugPrint('$NativeAd loaded.');
|
|
102
|
-
widget.backend.triggerControlEvent(widget.control.id, "load");
|
|
103
|
-
setState(() {
|
|
104
|
-
_isLoaded = true;
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
onAdFailedToLoad: (ad, error) {
|
|
108
|
-
widget.backend.triggerControlEvent(
|
|
109
|
-
widget.control.id, "error", error.toString());
|
|
110
|
-
// Dispose the ad here to free resources.
|
|
111
|
-
debugPrint('$NativeAd failedToLoad: $error');
|
|
112
|
-
ad.dispose();
|
|
113
|
-
},
|
|
114
|
-
onAdClicked: (ad) {
|
|
115
|
-
widget.backend.triggerControlEvent(widget.control.id, "click");
|
|
116
|
-
},
|
|
117
|
-
onAdImpression: (ad) {
|
|
118
|
-
widget.backend
|
|
119
|
-
.triggerControlEvent(widget.control.id, "impression");
|
|
120
|
-
},
|
|
121
|
-
onAdClosed: (ad) {
|
|
122
|
-
widget.backend.triggerControlEvent(widget.control.id, "close");
|
|
123
|
-
},
|
|
124
|
-
onAdOpened: (ad) {
|
|
125
|
-
widget.backend.triggerControlEvent(widget.control.id, "open");
|
|
126
|
-
},
|
|
127
|
-
onAdWillDismissScreen: (ad) {
|
|
128
|
-
widget.backend
|
|
129
|
-
.triggerControlEvent(widget.control.id, "willDismiss");
|
|
130
|
-
},
|
|
131
|
-
onPaidEvent: (ad, valueMicros, precision, currencyCode) {
|
|
132
|
-
widget.backend.triggerControlEvent(
|
|
133
|
-
widget.control.id,
|
|
134
|
-
"paidEvent",
|
|
135
|
-
jsonEncode({
|
|
136
|
-
"value_micros": valueMicros,
|
|
137
|
-
"precision": precision,
|
|
138
|
-
"currency_code": currencyCode
|
|
139
|
-
}));
|
|
140
|
-
},
|
|
141
|
-
),
|
|
142
|
-
request: const AdRequest(),
|
|
143
|
-
nativeTemplateStyle: nativeTemplateStyle);
|
|
144
|
-
|
|
145
|
-
if (!_isLoaded) {
|
|
146
|
-
nativeAd.load();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return constrainedControl(
|
|
150
|
-
context, AdWidget(ad: nativeAd), widget.parent, widget.control);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import 'dart:convert';
|
|
2
|
-
|
|
3
|
-
import 'package:collection/collection.dart';
|
|
4
|
-
import 'package:flet/flet.dart';
|
|
5
|
-
import 'package:flutter/material.dart';
|
|
6
|
-
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
|
7
|
-
|
|
8
|
-
TemplateType? parseTemplateType(String? value, [TemplateType? defaultValue]) {
|
|
9
|
-
if (value == null) return defaultValue;
|
|
10
|
-
return TemplateType.values.firstWhereOrNull(
|
|
11
|
-
(e) => e.toString().toLowerCase() == value.toLowerCase()) ??
|
|
12
|
-
defaultValue;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
NativeTemplateFontStyle? parseNativeTemplateFontStyle(String? value,
|
|
16
|
-
[NativeTemplateFontStyle? defaultValue]) {
|
|
17
|
-
if (value == null) return defaultValue;
|
|
18
|
-
return NativeTemplateFontStyle.values.firstWhereOrNull(
|
|
19
|
-
(e) => e.toString().toLowerCase() == value.toLowerCase()) ??
|
|
20
|
-
defaultValue;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
NativeTemplateTextStyle? parseNativeTemplateTextStyle(
|
|
24
|
-
ThemeData theme, Control control, String propName) {
|
|
25
|
-
dynamic j;
|
|
26
|
-
var v = control.attrString(propName, null);
|
|
27
|
-
if (v == null) return null;
|
|
28
|
-
|
|
29
|
-
j = json.decode(v);
|
|
30
|
-
return nativeTextStyleFromJson(theme, j);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
NativeTemplateTextStyle? nativeTextStyleFromJson(
|
|
34
|
-
ThemeData theme, Map<String, dynamic>? json) {
|
|
35
|
-
if (json == null) return null;
|
|
36
|
-
return NativeTemplateTextStyle(
|
|
37
|
-
size: parseDouble(json["size"]),
|
|
38
|
-
textColor: parseColor(theme, json["color"]),
|
|
39
|
-
backgroundColor: parseColor(theme, json["bgColor"]),
|
|
40
|
-
style: parseNativeTemplateFontStyle(json["style"]),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
NativeTemplateStyle? parseNativeTemplateStyle(
|
|
45
|
-
ThemeData theme, Control control, String propName) {
|
|
46
|
-
dynamic j;
|
|
47
|
-
var v = control.attrString(propName, null);
|
|
48
|
-
if (v == null) return null;
|
|
49
|
-
|
|
50
|
-
j = json.decode(v);
|
|
51
|
-
return nativeTemplateStyleFromJson(theme, j);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
NativeTemplateStyle nativeTemplateStyleFromJson(
|
|
55
|
-
ThemeData theme, Map<String, dynamic> json) {
|
|
56
|
-
return NativeTemplateStyle(
|
|
57
|
-
templateType:
|
|
58
|
-
parseTemplateType(json["template_type"], TemplateType.medium)!,
|
|
59
|
-
mainBackgroundColor: parseColor(theme, "main_bgcolor"),
|
|
60
|
-
cornerRadius: parseDouble(json["corner_radius"]),
|
|
61
|
-
callToActionTextStyle:
|
|
62
|
-
nativeTextStyleFromJson(theme, json["call_to_action_text_style"]),
|
|
63
|
-
primaryTextStyle:
|
|
64
|
-
nativeTextStyleFromJson(theme, json["primary_text_style"]),
|
|
65
|
-
secondaryTextStyle:
|
|
66
|
-
nativeTextStyleFromJson(theme, json["secondary_text_style"]),
|
|
67
|
-
tertiaryTextStyle:
|
|
68
|
-
nativeTextStyleFromJson(theme, json["tertiary_text_style"]));
|
|
69
|
-
}
|