Flutter数据处理与Excel集成插件exelbid_plugin的使用
Flutter数据处理与Excel集成插件exelbid_plugin的使用
目录
版本历史
1.0.4
- 其他bug修复
开始之前
- Exelbid建议在广告请求后30分钟内完成曝光(曝光缓存时间)。如果曝光时间超过此时间,可能会根据广告活动导致曝光无效。
插件信息
- Flutter 3.102.0版本
SDK信息
- SDK信息请参阅以下链接:
开始使用
添加Flutter插件
命令行安装
通过以下命令添加依赖并安装:
flutter pub add exelbid_plugin
手动安装
在pubspec.yaml
文件中添加依赖:
dependencies:
exelbid_plugin: any
然后运行以下命令进行安装:
flutter pub get
Android设置
AndroidManifest设置
推荐权限设置:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
iOS设置
Info.plist设置
为了允许广告标识符和HTTP流量,需要在Info.plist
中设置以下内容:
- 打开Flutter项目的
ios/Runner/Info.plist
文件。 - 添加以下内容:
<key>NSUserTrackingUsageDescription</key>
<string>该应用为提供个性化广告将使用广告标识符。</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
广告标识符权限请求
在用户安装应用后,需要请求用户隐私保护权限。此权限仅需请求一次,并且在用户做出响应后不会再次请求。
import AppTrackingTransparency
...
@main
@objc class AppDelegate: FlutterAppDelegate {
...
override func applicationDidBecomeActive(_ application: UIApplication) {
super.applicationDidBecomeActive(application)
if #available(iOS 14.0, *) {
ATTrackingManager.requestTrackingAuthorization { _ in }
}
}
}
广告应用
- 创建Exelbid账户。
- 库存 -> 应用 -> 创建新应用
- 库存 -> 单元 -> 创建新单元
实例公共方法
为了提高广告效果,建议设置年龄和性别。
Key | Type | Default | Desc |
---|---|---|---|
adUnitId | String | 设置广告ID。 | |
coppa | bool? | false | 美国儿童在线隐私保护法规定,如果用户小于13岁,则限制个人数据用于广告投标。 |
listener | EBPAdListener? | null | 回调事件监听器。 |
横幅广告
横幅广告实例
Key | Type | Default | Desc |
---|---|---|---|
isFullWebView | bool? | true | 广告宽度设置为100%的webview绑定。 |
EBBannerAdView {
final String adUnitId;
final bool? isFullWebView;
final bool? coppa;
final bool? isTest;
}
示例
EBBannerAdView(
adUnitId: "<<Ad Unit Id>>",
listener: EBPBannerAdViewListener(
onLoadAd: () {
print("Banner onLoadAd");
}, onFailAd: (String? errorMessage) {
print("Banner onFailAd");
}, onClickAd: () {
print("Banner onClickAd");
}
)
)
横幅广告事件监听器
EBPBannerAdViewListener {
/// 广告请求成功
final Function() onLoadAd;
/// 广告请求失败 (无广告)
final Function(String? errorMessage) onFailAd;
/// 广告点击
final Function()? onClickAd;
}
全屏广告
全屏广告事件监听器
EBPInterstitialAdViewListener {
/// 广告请求成功
final Function() onLoadAd;
/// 广告请求失败 (无广告)
final Function(String? errorMessage) onFailAd;
/// 广告点击
final Function()? onClickAd;
/// 全屏广告显示后发送
final Function()? onInterstitialShow;
/// 全屏广告从屏幕上移除后发送
final Function()? onInterstitialDismiss;
}
全屏广告回调监听器设置
示例
ExelbidPlugin.shared.setInterstitialListener(EBPInterstitialAdViewListener(
onLoadAd: () {
print("Interstitial onLoadAd");
}, onFailAd: (String? errorMessage) {
print("Interstitial onFailAd");
}, onClickAd: () {
print("Interstitial onClickAd");
}, onInterstitialShow: () {
print("onInterstitialShow");
}, onInterstitialDismiss: () {
print("onInterstitialDismiss");
})
);
全屏广告请求
Future<void> loadInterstitial({
required String adUnitId,
bool? coppa,
bool? isTest
})
示例
ExelbidPlugin.shared.loadInterstitial(adUnitId: "<<Ad Unit Id>>");
全屏广告展示
在全屏广告初始化完成后,需要请求展示广告。
ExelbidPlugin.shared.showInterstitial();
原生广告
原生广告实例
Key | Type | Default | Desc |
---|---|---|---|
nativeAssets | EBNativeAssets? | null | 请求原生广告时所需的项目。 |
EBNativeAdView {
final Widget child;
final String adUnitId;
final List<String>? nativeAssets;
final bool? coppa;
final bool? isTest;
final EBPNativeAdViewListener? listener;
};
原生广告属性
class EBNativeAssets {
// 标题
static const String title = "title";
// 图标图像
static const String icon = "icon";
// 主图像
static const String main = "main";
// 描述
static const String desc = "desc";
// 点击按钮文本(诱导文本)
static const String ctatext = "ctatext";
}
示例
EBNativeAdView(
adUnitId: "<<Ad Unit Id>>",
nativeAssets: const [
EBNativeAssets.title,
EBNativeAssets.main,
EBNativeAssets.icon,
EBNativeAssets.ctatext,
],
listener: EBPNativeAdViewListener(
onLoadAd: () {
print("Native onLoadAd");
}, onFailAd: (String? errorMessage) {
print("Native onFailAd");
}, onClickAd: () {
print("Native onClickAd");
}
)
child: "<<Native Ad View UI>>"
)
原生广告UI
设置原生广告视图时,请参考以下内容以包含资产设置对象。
原生标题
EBNativeAdTtitle {
final TextStyle? style;
final TextAlign? textAlign;
final bool? softWrap;
final TextOverflow? overflow;
final int? maxLines;
}
原生描述
EBNativeAdDescription {
final TextStyle? style;
final TextAlign? textAlign;
final bool? softWrap;
final TextOverflow? overflow;
final int? maxLines;
}
原生主图像
EBNativeAdMainImage {
final double? width;
final double? height;
}
原生图标图像
EBNativeAdIconImage{
final double? width;
final double? height;
}
原生操作按钮
EBNativeAdCallToAction {
final ButtonStyle? style;
}
在线个性化广告隐私指南图标
EBNativeAdPrivacyInformationIconImage {
final double? width;
final double? height;
}
2017年7月,韩国广播通信委员会实施了《在线个性化广告隐私指南》,必须强制应用。根据广告主提供的广告类型(个性化广告与否),将决定是否显示信息图标(Opt-out)。请注意,显示广告信息图标的ImageView大小应设置为NxN(建议20x20)。
示例
Column(children: [
// 顶部图像及文本区域
const Row(children: [
SizedBox(
width: 48,
height: 48,
child: Center(
child: EBNativeAdIconImage(),
),
),
SizedBox(width: 10),
Expanded(
child: EBNativeAdTtitle(),
),
]),
const SizedBox(height: 10),
// 主图像视图
const Expanded(
child: SizedBox(
width: double.infinity,
child: Center(
child: Stack(children: [
EBNativeAdMainImage(),
Positioned(
right: 10,
top: 10,
child:
EBNativeAdPrivacyInformationIconImage(
width: 20,
height: 20,
),
),
]),
),
),
),
const SizedBox(height: 10),
// 按钮区域
Align(
alignment: Alignment.bottomRight,
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: const EBNativeAdCallToAction(
style: ButtonStyle(
backgroundColor:
WidgetStatePropertyAll<Color>(
Colors.white),
textStyle:
WidgetStatePropertyAll<TextStyle>(
TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold)),
),
),
),
),
])
原生广告事件监听器
EBPNativeAdViewListener {
/// 广告请求成功
final Function() onLoadAd;
/// 广告请求失败 (无广告)
final Function(String? errorMessage) onFailAd;
/// 广告点击
final Function()? onClickAd;
}
中介
使用Exelbid插件进行中介连接时,会根据每个应用程序中连接的广告SDK的最佳调用顺序进行响应。
中介网络
网络 | 中介类型 |
---|---|
Exelbid | EBMediationTypes.exelbid |
AdMob | EBMediationTypes.admob |
EBMediationTypes.facebook | |
AdFit | EBMediationTypes.adfit |
DigitalTurbine | EBMediationTypes.digitalturbine |
Pangle | EBMediationTypes.pangle |
TNK | EBMediationTypes.tnk |
AppLovin | EBMediationTypes.applovin |
MPartners | EBMediationTypes.mpartners |
中介设置及请求
中介实例
EBMediationManager {
final String mediationUnitId;
final List<String> mediationTypes;
final EBPMediationListener listener;
}
中介实例初始化
_mediationManager = EBMediationManager(
mediationUnitId: "<<Mediation Unit ID>>",
mediationTypes: [
EBMediationTypes.exelbid,
// 添加使用的中介网络
],
listener: EBPMediationListener(
onLoad: () {
// 成功获取中介列表
},
onError: (EBError error) {
// 中介错误,异常处理(无广告处理)
},
onEmpty: () {
// 中介列表为空或遍历完成(无广告处理)
},
onNext: (EBMediation mediation) {
// 检查要使用的中介网络并请求广告
if (mediation.networkId == EBMediationTypes.exelbid) {
// 使用传递的unitId按networkId请求广告
} else {
// 没有匹配的网络则请求下一个中介
_mediationManager.nextMediation();
}
},
),
);
中介回调监听器
// 中介回调监听器
class EBPMediationListener {
// 成功获取中介列表
final Function() onLoad;
// 下一个顺序中介查询
final Function(EBMediation mediation) onNext;
// 中介列表为空或遍历完成(无广告处理)
final Function() onEmpty;
// 中介错误,异常处理(无广告处理)
final Function(EBError error) onError;
}
中介数据
class EBMediation {
final String networkId;
final String unitId;
}
中介请求及列表遍历
// 获取中介列表(EBPMediationListener -> onLoad)
_mediationManager.loadMediation();
// 获取中介信息(EBPMediationListener -> onNext or onEmpty)
_mediationManager.nextMediation();
提示: 如果第三方广告请求失败或无广告,请调用下一个中介。
_mediationManager.loadMediation();
更多关于Flutter数据处理与Excel集成插件exelbid_plugin的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter数据处理与Excel集成插件exelbid_plugin的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
在Flutter中处理数据并与Excel集成,可以使用插件excelbid_plugin
。这个插件允许你在Flutter应用中读取和写入Excel文件。以下是使用excelbid_plugin
的基本步骤:
1. 添加依赖
首先,你需要在pubspec.yaml
文件中添加excelbid_plugin
的依赖:
dependencies:
flutter:
sdk: flutter
excelbid_plugin: ^1.0.0 # 请使用最新版本
然后运行flutter pub get
来安装依赖。
2. 导入插件
在你的Dart文件中导入插件:
import 'package:excelbid_plugin/excelbid_plugin.dart';
3. 读取Excel文件
你可以使用ExcelBidPlugin
来读取Excel文件中的数据。以下是一个简单的示例:
void readExcel() async {
// 选择Excel文件
String filePath = 'path/to/your/excel_file.xlsx';
// 读取Excel文件
var excel = await ExcelBidPlugin.readExcel(filePath);
// 获取工作表
var sheet = excel['Sheet1']; // 假设你的工作表名称为 'Sheet1'
// 遍历单元格
for (var row in sheet) {
for (var cell in row) {
print(cell.value);
}
}
}
4. 写入Excel文件
你也可以使用ExcelBidPlugin
来创建或修改Excel文件并保存:
void writeExcel() async {
// 创建一个新的Excel对象
var excel = ExcelBidPlugin.createExcel();
// 添加一个工作表
var sheet = excel['Sheet1'];
// 写入数据
sheet.cell(CellIndex.indexByString("A1")).value = "Hello";
sheet.cell(CellIndex.indexByString("B1")).value = "World";
// 保存Excel文件
String filePath = 'path/to/save/excel_file.xlsx';
await ExcelBidPlugin.saveExcel(excel, filePath);
print('Excel文件已保存到 $filePath');
}
5. 处理Excel数据
你可以根据需要对读取的数据进行处理,或者将处理后的数据写入Excel文件。
6. 使用示例
以下是一个完整的示例,展示了如何读取和写入Excel文件:
import 'package:flutter/material.dart';
import 'package:excelbid_plugin/excelbid_plugin.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('ExcelBid Plugin Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: readExcel,
child: Text('Read Excel'),
),
ElevatedButton(
onPressed: writeExcel,
child: Text('Write Excel'),
),
],
),
),
),
);
}
void readExcel() async {
String filePath = 'path/to/your/excel_file.xlsx';
var excel = await ExcelBidPlugin.readExcel(filePath);
var sheet = excel['Sheet1'];
for (var row in sheet) {
for (var cell in row) {
print(cell.value);
}
}
}
void writeExcel() async {
var excel = ExcelBidPlugin.createExcel();
var sheet = excel['Sheet1'];
sheet.cell(CellIndex.indexByString("A1")).value = "Hello";
sheet.cell(CellIndex.indexByString("B1")).value = "World";
String filePath = 'path/to/save/excel_file.xlsx';
await ExcelBidPlugin.saveExcel(excel, filePath);
print('Excel文件已保存到 $filePath');
}
}