696 lines
26 KiB
Dart
696 lines
26 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:web_tools/web_tools.dart';
|
||
|
||
class WebToolsExamplePage extends StatefulWidget {
|
||
const WebToolsExamplePage({super.key});
|
||
|
||
@override
|
||
State<WebToolsExamplePage> createState() => _WebToolsExamplePageState();
|
||
}
|
||
|
||
class _WebToolsExamplePageState extends State<WebToolsExamplePage> {
|
||
final FlutterBridge bridge = FlutterBridge.instance;
|
||
|
||
// 控制器用于输入参数
|
||
final TextEditingController gameIdController = TextEditingController()
|
||
..text = '311';
|
||
final TextEditingController userIdController = TextEditingController()
|
||
..text = 'f894609cbab2440c8b2c5161049ec881';
|
||
final TextEditingController googleProductIdController =
|
||
TextEditingController()..text = '70055';
|
||
final TextEditingController iosProductIdController = TextEditingController();
|
||
final TextEditingController pathController = TextEditingController();
|
||
final TextEditingController titleController = TextEditingController();
|
||
final TextEditingController gameCodeController = TextEditingController()
|
||
..text = '310';
|
||
final TextEditingController activityIdController = TextEditingController()
|
||
..text = '83';
|
||
final TextEditingController schemeController = TextEditingController();
|
||
final TextEditingController linkUrlController = TextEditingController();
|
||
|
||
@override
|
||
void dispose() {
|
||
gameIdController.dispose();
|
||
userIdController.dispose();
|
||
googleProductIdController.dispose();
|
||
iosProductIdController.dispose();
|
||
pathController.dispose();
|
||
titleController.dispose();
|
||
gameCodeController.dispose();
|
||
activityIdController.dispose();
|
||
schemeController.dispose();
|
||
linkUrlController.dispose();
|
||
super.dispose();
|
||
}
|
||
|
||
Widget _buildMethodTile(
|
||
String title, String description, VoidCallback onPressed) {
|
||
return ListTile(
|
||
title: Text(title, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||
subtitle: Text(description),
|
||
trailing: ElevatedButton(
|
||
onPressed: onPressed,
|
||
child: const Text('调用'),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildMethodWithInputTile(
|
||
String title,
|
||
String description,
|
||
TextEditingController controller,
|
||
String hint,
|
||
VoidCallback onPressed,
|
||
) {
|
||
return ListTile(
|
||
title: Text(title, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||
subtitle: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(description),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: controller,
|
||
decoration: InputDecoration(
|
||
hintText: hint,
|
||
border: const OutlineInputBorder(),
|
||
contentPadding:
|
||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
trailing: ElevatedButton(
|
||
onPressed: onPressed,
|
||
child: const Text('调用'),
|
||
),
|
||
);
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
title: const Text('Web Tools 交互方法示例'),
|
||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||
),
|
||
body: ListView(
|
||
padding: const EdgeInsets.all(16),
|
||
children: [
|
||
// 游戏相关模块
|
||
ExpansionTile(
|
||
title: const Text('游戏相关方法'),
|
||
children: [
|
||
_buildMethodTile(
|
||
'关闭页面',
|
||
'关闭当前网页',
|
||
() => bridge.close(),
|
||
),
|
||
_buildMethodTile(
|
||
'关闭游戏页面',
|
||
'关闭游戏页面左上角返回',
|
||
() => bridge.sendToFlutter(ToFlutterAppEnum.gameExit.code, {}),
|
||
),
|
||
_buildMethodTile(
|
||
'游戏结束',
|
||
'通知原生游戏已结束',
|
||
() => bridge.gameOver(),
|
||
),
|
||
_buildMethodWithInputTile(
|
||
'创建游戏',
|
||
'创建指定ID的游戏',
|
||
gameIdController,
|
||
'输入游戏ID',
|
||
() {
|
||
if (gameIdController.text.isNotEmpty) {
|
||
bridge.createGame(gameIdController.text);
|
||
} else {
|
||
bridge.createGame("311");
|
||
}
|
||
},
|
||
),
|
||
_buildMethodWithInputTile(
|
||
'想玩游戏',
|
||
'表达想玩指定游戏的意愿',
|
||
gameIdController,
|
||
'输入游戏ID',
|
||
() {
|
||
if (gameIdController.text.isNotEmpty) {
|
||
bridge.wantToPlay(gameIdController.text);
|
||
}
|
||
},
|
||
),
|
||
_buildMethodWithInputTile(
|
||
'跳转到游戏详情页',
|
||
'不同的值代表不同的游戏',
|
||
gameIdController,
|
||
'gameType',
|
||
() {
|
||
if (gameIdController.text.isNotEmpty) {
|
||
bridge.sendToFlutter(ToFlutterAppEnum.gameType.code,
|
||
{"gameType": gameIdController.text});
|
||
}
|
||
},
|
||
),
|
||
_buildMethodWithInputTile(
|
||
'检查游戏状态',
|
||
'检查指定游戏的状态',
|
||
gameCodeController,
|
||
'输入游戏代码',
|
||
() {
|
||
if (gameCodeController.text.isNotEmpty) {
|
||
bridge.checkGameState(gameCodeController.text);
|
||
}
|
||
},
|
||
),
|
||
],
|
||
),
|
||
|
||
// 充值支付模块
|
||
ExpansionTile(
|
||
title: const Text('充值支付方法'),
|
||
children: [
|
||
_buildMethodTile(
|
||
'前往充值',
|
||
'跳转到充值页面',
|
||
() => bridge.toRecharge(),
|
||
),
|
||
_buildMethodTile(
|
||
'前往红钻充值',
|
||
'跳转到红钻充值页面',
|
||
() => bridge.toRedDiamond(),
|
||
),
|
||
_buildMethodTile(
|
||
'定向充值',
|
||
'直接唤起内购付费框',
|
||
() => bridge.sendToFlutter(
|
||
ToFlutterAppEnum.rechargeItem.code, {"productId": "70055"}),
|
||
),
|
||
ListTile(
|
||
title: const Text('月卡支付',
|
||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||
subtitle: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text('跳转到月卡支付页面'),
|
||
const SizedBox(height: 8),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: TextField(
|
||
controller: googleProductIdController,
|
||
decoration: const InputDecoration(
|
||
hintText: 'Google产品ID',
|
||
border: OutlineInputBorder(),
|
||
contentPadding: EdgeInsets.symmetric(
|
||
horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(width: 8),
|
||
Expanded(
|
||
child: TextField(
|
||
controller: iosProductIdController,
|
||
decoration: const InputDecoration(
|
||
hintText: 'iOS产品ID',
|
||
border: OutlineInputBorder(),
|
||
contentPadding: EdgeInsets.symmetric(
|
||
horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: userIdController,
|
||
decoration: const InputDecoration(
|
||
hintText: '其他用户ID (可选)',
|
||
border: OutlineInputBorder(),
|
||
contentPadding:
|
||
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
trailing: ElevatedButton(
|
||
onPressed: () {
|
||
if (googleProductIdController.text.isNotEmpty &&
|
||
iosProductIdController.text.isNotEmpty) {
|
||
bridge.toMonthCardPay(
|
||
googleProductIdController.text,
|
||
iosProductIdController.text,
|
||
otherUserId: userIdController.text,
|
||
);
|
||
}
|
||
},
|
||
child: const Text('调用'),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
|
||
// 页面导航模块
|
||
ExpansionTile(
|
||
title: const Text('页面导航方法'),
|
||
children: [
|
||
ListTile(
|
||
title: const Text('跳转到H5页面',
|
||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||
subtitle: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text('在原生App中跳转到H5页面'),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: pathController,
|
||
decoration: const InputDecoration(
|
||
hintText: '页面路径',
|
||
border: OutlineInputBorder(),
|
||
contentPadding:
|
||
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: titleController,
|
||
decoration: const InputDecoration(
|
||
hintText: '页面标题',
|
||
border: OutlineInputBorder(),
|
||
contentPadding:
|
||
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
trailing: ElevatedButton(
|
||
onPressed: () {
|
||
if (pathController.text.isNotEmpty &&
|
||
titleController.text.isNotEmpty) {
|
||
bridge.jumpToH5(
|
||
pathController.text, titleController.text);
|
||
}
|
||
},
|
||
child: const Text('调用'),
|
||
),
|
||
),
|
||
_buildMethodWithInputTile(
|
||
'前往用户主页',
|
||
'跳转到指定用户的主页',
|
||
userIdController,
|
||
'输入用户ID',
|
||
() {
|
||
if (userIdController.text.isNotEmpty) {
|
||
bridge.toHomepage(userIdController.text);
|
||
}
|
||
},
|
||
),
|
||
_buildMethodTile("恩爱节活动", "恩爱节活动跳转选择好友 1:cp 2:告白 3:组队", () {
|
||
bridge.sendToFlutter(
|
||
ToFlutterAppEnum.lovingDayChooseFriend.code, {});
|
||
}),
|
||
ListTile(
|
||
title: const Text('跳转到网页',
|
||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||
subtitle: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text('在原生App中打开网页'),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: linkUrlController,
|
||
decoration: const InputDecoration(
|
||
hintText: '网页链接',
|
||
border: OutlineInputBorder(),
|
||
contentPadding:
|
||
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: activityIdController,
|
||
decoration: const InputDecoration(
|
||
hintText: '活动ID',
|
||
border: OutlineInputBorder(),
|
||
contentPadding:
|
||
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
trailing: ElevatedButton(
|
||
onPressed: () {
|
||
if (linkUrlController.text.isNotEmpty &&
|
||
activityIdController.text.isNotEmpty) {
|
||
bridge.taskToWebViewPage(
|
||
linkUrl: linkUrlController.text,
|
||
activityId: activityIdController.text,
|
||
);
|
||
}
|
||
},
|
||
child: const Text('调用'),
|
||
),
|
||
),
|
||
ListTile(
|
||
title: const Text('解析URL并跳转',
|
||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||
subtitle: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text('解析scheme URL并跳转'),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: schemeController,
|
||
decoration: const InputDecoration(
|
||
hintText: 'Scheme URL',
|
||
border: OutlineInputBorder(),
|
||
contentPadding:
|
||
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
TextField(
|
||
controller: activityIdController,
|
||
decoration: const InputDecoration(
|
||
hintText: '活动ID',
|
||
border: OutlineInputBorder(),
|
||
contentPadding:
|
||
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
trailing: ElevatedButton(
|
||
onPressed: () {
|
||
if (schemeController.text.isNotEmpty &&
|
||
activityIdController.text.isNotEmpty) {
|
||
bridge.taskCommandJump(
|
||
scheme: schemeController.text,
|
||
activityId: activityIdController.text,
|
||
);
|
||
}
|
||
},
|
||
child: const Text('调用'),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
|
||
// 分享功能模块
|
||
ExpansionTile(
|
||
title: const Text('分享功能'),
|
||
children: [
|
||
_buildMethodWithInputTile(
|
||
'分享(通用分享)',
|
||
'分享活动,需要活动ID',
|
||
activityIdController,
|
||
'输入活动ID',
|
||
() {
|
||
if (activityIdController.text.isNotEmpty) {
|
||
bridge.share(
|
||
activityId: activityIdController.text,
|
||
needShareReport: true,
|
||
);
|
||
}
|
||
},
|
||
),
|
||
_buildMethodWithInputTile(
|
||
'分享(带卡片分享)',
|
||
'分享活动,需要活动ID',
|
||
activityIdController,
|
||
'输入活动ID',
|
||
() {
|
||
if (activityIdController.text.isNotEmpty) {
|
||
bridge.share(
|
||
activityId: activityIdController.text,
|
||
needShareReport: true,
|
||
shareCardModel: ShareCardModel(
|
||
activityIcon:
|
||
"app/img/local/new_year_share_content_bg_en_th.webp",
|
||
activityDesc: "这只是一个示例"));
|
||
}
|
||
},
|
||
),
|
||
],
|
||
),
|
||
|
||
// 直播互动模块
|
||
ExpansionTile(
|
||
title: const Text('直播互动方法'),
|
||
children: [
|
||
_buildMethodTile(
|
||
'检查开播',
|
||
'检查是否可以开始直播',
|
||
() => bridge.checkStartBroadcaster(),
|
||
),
|
||
_buildMethodTile(
|
||
'直播间发言任务',
|
||
'触发直播间发言任务',
|
||
() => bridge.taskLiveRoomChat(),
|
||
),
|
||
_buildMethodTile(
|
||
'直播间送礼任务',
|
||
'触发直播间送礼任务',
|
||
() => bridge.taskLiveRoomGift(),
|
||
),
|
||
_buildMethodTile(
|
||
'直播间其他任务',
|
||
'触发直播间其他任务',
|
||
() => bridge.taskLiveRoomOther(),
|
||
),
|
||
],
|
||
),
|
||
|
||
// 任务系统模块
|
||
ExpansionTile(
|
||
title: const Text('任务系统方法'),
|
||
children: [
|
||
_buildMethodTile(
|
||
'完善个人信息',
|
||
'跳转到完善个人信息页面',
|
||
() => bridge.shouldCompleteProfile(),
|
||
),
|
||
_buildMethodTile(
|
||
'观看时长任务',
|
||
'触发观看时长任务',
|
||
() => bridge.shouldWatchDuration(),
|
||
),
|
||
_buildMethodTile(
|
||
'发送公屏消息任务',
|
||
'触发发送公屏消息任务',
|
||
() => bridge.shouldSendPublicMessage(),
|
||
),
|
||
_buildMethodTile(
|
||
'上麦互动任务',
|
||
'触发上麦互动任务',
|
||
() => bridge.shouldMicInteraction(),
|
||
),
|
||
_buildMethodTile(
|
||
'发送私聊消息任务',
|
||
'触发发送私聊消息任务',
|
||
() => bridge.shouldSendPrivateMessage(),
|
||
),
|
||
_buildMethodTile(
|
||
'发布动态任务',
|
||
'触发发布动态任务',
|
||
() => bridge.shouldPostFeed(),
|
||
),
|
||
_buildMethodTile(
|
||
'分享房间任务',
|
||
'触发分享房间任务',
|
||
() => bridge.shouldShareRoom(),
|
||
),
|
||
_buildMethodTile(
|
||
'佩戴装扮任务',
|
||
'触发佩戴装扮任务',
|
||
() => bridge.shouldWearDecoration(),
|
||
),
|
||
_buildMethodTile(
|
||
'前往语音房任务',
|
||
'触发前往语音房任务',
|
||
() => bridge.shouldGoToVoiceRoom(),
|
||
),
|
||
_buildMethodTile(
|
||
'观看直播',
|
||
'触发前往语音房任务有-》 收藏房间 | 关注主播 | 发送房间消息 ',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType.taskKeyWatchLive.code,
|
||
// taskKeyCollectRoom | taskKeyFollowUser | taskKeySendRoomMessage
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'赠送礼物',
|
||
'触发前往语音房任务 && (打开礼物面板 or 赠送指定礼物 or 打开我的背包) ',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType.taskKeySendGift
|
||
.code, // taskKeySendGiftId | taskKeySendBackpackGift
|
||
...{"targetId": ""}
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'我想玩 XX游戏',
|
||
'触发前往语音房任务 && 发送我想玩 XX游戏',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType
|
||
.taskKeyPlayGame.code, // taskKeySendGiftId
|
||
...{"targetId": ""}
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'发红包',
|
||
'触发前往语音房任务 && 发红包',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": "TaskKeySendRedPack",
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'发送私聊消息',
|
||
'聊天 Tab ',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType
|
||
.taskKeySendPrivateMessage.code, // taskKeySendGiftId
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'参与动态话题',
|
||
'比传参数 topicTitle',
|
||
() => bridge.commonInteraction({
|
||
"interactionType":
|
||
WebInteractionType.taskKeyTimelineTopic.code,
|
||
...{
|
||
"topicTitle": "",
|
||
"targetId": "",
|
||
"content": "",
|
||
"image": "",
|
||
"textId": ""
|
||
}
|
||
// taskKeySendGiftId
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'点赞动态 or 评论动态',
|
||
'切换 圈子 Tab',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType
|
||
.taskKeyLikeTimeline.code, // taskKeyReplayTimeline
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'签到',
|
||
'首页签到弹框',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType
|
||
.taskKeySignIn.code, // taskKeyReplayTimeline
|
||
|
||
// taskKeySendGiftId
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'其他页面',
|
||
'进入其他h5页面',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType
|
||
.taskKeyOtherPage.code, // taskKeyReplayTimeline
|
||
|
||
// taskKeySendGiftId
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'我的钱包页面',
|
||
'我的钱包页面',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType
|
||
.taskKeyMineWallet.code, // taskKeyReplayTimeline
|
||
|
||
// taskKeySendGiftId
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'我的背包',
|
||
'我的装扮背包页面(或者是称号)',
|
||
() => bridge.commonInteraction({
|
||
"interactionType": WebInteractionType
|
||
.taskKeyMineBackpack.code, // taskKeyReplayTimeline
|
||
|
||
// taskKeySendGiftId
|
||
}),
|
||
),
|
||
],
|
||
),
|
||
|
||
// 其他功能模块
|
||
ExpansionTile(
|
||
title: const Text('其他功能方法'),
|
||
children: [
|
||
_buildMethodTile(
|
||
'专属见面礼',
|
||
'触发专属见面礼任务',
|
||
() => bridge.taskInviteCodeGift(),
|
||
),
|
||
_buildMethodTile(
|
||
'跳转从业者申请',
|
||
'跳转到从业者申请页面',
|
||
() => bridge.toApplyAdmissionPage(),
|
||
),
|
||
_buildMethodTile(
|
||
'直播预约设置',
|
||
'打开直播预约设置',
|
||
() => bridge.shouLiveBookingPicker(),
|
||
),
|
||
_buildMethodTile(
|
||
'观时礼刷新宝箱数据',
|
||
'观时礼刷新宝箱数据',
|
||
() =>
|
||
bridge.sendToFlutter(ToFlutterAppEnum.closeObserving.code, {
|
||
"updateType": "1" // 1 刷新整个挂件数据,2刷新观时礼的宝箱列表数据
|
||
}),
|
||
),
|
||
_buildMethodTile(
|
||
'翻译',
|
||
'多语言翻译',
|
||
() => bridge.sendRequest(
|
||
sendType: ToFlutterAppEnum.translateRequest,
|
||
listenType: FromFlutterAppEnum.translateResult,
|
||
params: {"text0001": "text0001"},
|
||
onSuccess: (dic) {}),
|
||
),
|
||
ListTile(
|
||
title: const Text('通用交互',
|
||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||
subtitle: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text('通用交互方法,可以传递自定义参数'),
|
||
const SizedBox(height: 8),
|
||
Container(
|
||
padding: const EdgeInsets.all(12),
|
||
decoration: BoxDecoration(
|
||
border: Border.all(color: Colors.grey),
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
child: const Text(
|
||
'示例参数:{"action": "custom_action", "data": "value"}',
|
||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
trailing: ElevatedButton(
|
||
onPressed: () {
|
||
bridge.commonInteraction({
|
||
"action": "custom_action",
|
||
"data": "example_value",
|
||
"timestamp": DateTime.now().toIso8601String(),
|
||
});
|
||
},
|
||
child: const Text('调用'),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|