このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

Flutter

Plugin Feature

From tencent_cloud_chat_sdk version 5.1.5 onwards, you can integrate the voting plugin tencent_cloud_chat_vote_plugin provided by Tencent Cloud Instant Messaging. This plugin is closed-source. After integration, you can integrate the voting feature in groups (except Community and AVChatRoom). The voting feature includes initiating (single-choice, multiple-choice) votes, viewing voting results, and participating in voting. The voting capability is interoperable between Flutter and Native.

Environment and Version

This plugin depends on other plugins and the environment
Flutter 3.10.0 or later
tencent_cloud_chat_sdk 5.1.5 or later

Plugin Introduction

You can introduce the voting plugin tencent_cloud_chat_vote_plugin 1.0.2 into the project via pub:
// Integrate the latest version
pub add tencent_cloud_chat_vote_plugin
// Integrate a specific version by adding it to the dependencies field in the project's pubspec.yaml
tencent_cloud_chat_vote_plugin: "version"

Core Components

Plugin Integration

Initializing the plugin

// Place after logging into IM

await TencentCloudChatVotePlugin.initPlugin();

Creating a vote

Users can create a vote by clicking the vote button.
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});

@override
State<StatefulWidget> createState() => VoteCreateExampleState();
}

class VoteCreateExampleState extends State {
@override
Widget 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);
},
),
),
);
}
}
TencentCloudChatVoteCreate parameter description
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.

Parsing the voting message

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});

@override
State<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;
@override
void initState() {
super.initState();
Future.delayed(
const Duration(
milliseconds: 300,
), () {
setState(() {
isEnd = true;
});
});
// Show component after page animation ends
getTestV2TimMessage();
}

@override
Widget 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"),
),
);
}
}

TencentCloudChatVoteMessage parameter description
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

Viewing 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,
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(option.option),
),
body: Padding(
padding: const EdgeInsets.all(16),
child: TencentCloudChatVoteDetail(
option: option,
data: data,
),
),
);
}
}

TencentCloudChatVoteDetail parameter description
Parameter
Description
option
TencentCloudChatVoteDataOption type, voting details data, obtained when TencentCloudChatVoteMessage is clicked.
data
TencentCloudChatVoteLogic type, obtained when TencentCloudChatVoteMessage is clicked.