// 集成最新版本pub add tencent_cloud_chat_vote_plugin// 集成指定版本,在项目pubspec.yaml中dependencies字段加入tencent_cloud_chat_vote_plugin: "version"
// 放在登录IM后await TencentCloudChatVotePlugin.initPlugin();
import 'package:example/config.dart';import 'package:flutter/material.dart';import 'package:tencent_cloud_chat_vote_plugin/components/vote_create/vote_create.dart';class VoteCreateExample extends StatefulWidget {const VoteCreateExample({super.key});@overrideState<StatefulWidget> createState() => VoteCreateExampleState();}class VoteCreateExampleState extends State {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text("创建投票"),),body: Container(padding: const EdgeInsets.all(16),child: TencentCloudChatVoteCreate(groupID: ExampleConfig.testGruopID,onCreateVoteSuccess: () {Navigator.pop(context);},),),);}}
参数 | 说明 |
groupID | 需要创建投票的群 ID,同 IM 群 ID,Community 和 AVChatRoom 除外。 |
onCreateVoteSuccess | 创建投票成功回调。 |
import 'package:example/config.dart';import 'package:example/vote_detail_example.dart';import 'package:flutter/material.dart';import 'package:tencent_cloud_chat_sdk/enum/history_msg_get_type_enum.dart';import 'package:tencent_cloud_chat_sdk/models/v2_tim_message.dart';import 'package:tencent_cloud_chat_sdk/models/v2_tim_value_callback.dart';import 'package:tencent_cloud_chat_sdk/tencent_im_sdk_plugin.dart';import 'package:tencent_cloud_chat_vote_plugin/tencent_cloud_chat_vote_plugin.dart';class VoteMessageExample extends StatefulWidget {const VoteMessageExample({super.key});@overrideState<StatefulWidget> createState() => VoteMessageExampleState();}class VoteMessageExampleState extends State {V2TimMessage? message;getTestV2TimMessage() async {V2TimValueCallback<List<V2TimMessage>> messageListRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().getHistoryMessageList(count: 1,groupID: ExampleConfig.testGruopID,getType: HistoryMsgGetTypeEnum.V2TIM_GET_CLOUD_OLDER_MSG,);if (messageListRes.code == 0) {if (messageListRes.data != null) {if (messageListRes.data!.isNotEmpty) {setState(() {message = messageListRes.data!.first;});}}}}bool isEnd = false;@overridevoid initState() {super.initState();Future.delayed(const Duration(milliseconds: 300,), () {setState(() {isEnd = true;});});// 页面运动结束再显示组件getTestV2TimMessage();}@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text("投票消息体"),),body: !isEnd? Container(): message != null? TencentCloudChatVoteMessage(message: message!,onTap: (TencentCloudChatVoteDataOptoin option,TencentCloudChatVoteLogic data,) {print(data.voteData.toJson());Navigator.push(context,MaterialPageRoute(builder: (context) => VoteDetailExample(option: option,data: data,),),);},): const Center(child: Text("未获取到正确的Message实例"),),);}}
参数 | 说明 |
message | 投票消息,V2TimMessage 类型。 |
onTap | 单击投票回调,当投票为公开且实名时,可以打开群投票详情。 |
import 'package:flutter/material.dart';import 'package:tencent_cloud_chat_vote_plugin/tencent_cloud_chat_vote_plugin.dart';class VoteDetailExample extends StatelessWidget {final TencentCloudChatVoteDataOptoin option;final TencentCloudChatVoteLogic data;const VoteDetailExample({super.key,required this.option,required this.data,});@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text(option.option),),body: Padding(padding: const EdgeInsets.all(16),child: TencentCloudChatVoteDetail(option: option,data: data,),),);}}
参数 | 说明 |
option | TencentCloudChatVoteDataOption 类型,投票详情数据,由 TencentCloudChatVoteMessage 单击时获取。 |
data | TencentCloudChatVoteLogic 类型由 TencentCloudChatVoteMessage 点击时获取。 |
本页内容是否解决了您的问题?