// Integrate the latest versionpub add tencent_cloud_chat_vote_plugin// Integrate a specific version by adding it to the dependencies field in the project's pubspec.yamltencent_cloud_chat_vote_plugin: "version"
// Place after logging into IMawait 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("Creating a vote")),body: Container(padding: const EdgeInsets.all(16),child: TencentCloudChatVoteCreate(groupID: ExampleConfig.testGruopID,onCreateVoteSuccess: () {Navigator.pop(context);},),),);}}
Parameter | Description |
groupID | The group ID for creating a vote, same as the IM group ID, except for Community and AVChatRoom. |
onCreateVoteSuccess | create voting success callback. |
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;});});// Show component after page animation endsgetTestV2TimMessage();}@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text("Voting message body"),),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("Failed to get a valid Message instance"),),);}}
Parameter | Description |
message | Voting message, V2TimMessage type |
onTap | Clicking the voting callback, when the vote is public and real-name, you can open group voting details |
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,),),);}}
Parameter | Description |
option | TencentCloudChatVoteDataOption type, voting details data, obtained when TencentCloudChatVoteMessage is clicked. |
data | TencentCloudChatVoteLogic type, obtained when TencentCloudChatVoteMessage is clicked. |
この記事はお役に立ちましたか?