tencent cloud

Feedback

Last updated: 2025-01-23 11:43:54

    Plugin Feature

    From version 5.1.5 of tencent_cloud_chat_sdk onwards, you can integrate the vote plugin tencent_cloud_chat_vote_plugin provided by Tencent Cloud Instant Messaging. It is a closed-source plugin. After this plugin is integrated, you can integrate the vote feature into groups (except Community and AVChatRoom) to initiate (single-choice and multiple-choice) a vote, view vote results, and participate in a vote. The vote feature is interoperable between Flutter and Native.

    Environment and Version

    This plugin depends on other plugins and environments.
    Flutter 3.10.0 or later
    tencent_cloud_chat_sdk 5.1.5 or later

    Plugin Introduction

    You can introduce the vote plugin tencent_cloud_chat_vote_plugin 1.0.2 into a 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 ID of the group for vote creation, the same as the IM group ID (except for Community and AVChatRoom).
    onCreateVoteSuccess
    Callback for successful vote creation.

    Parsing Vote Messages

    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("Vote 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
    Vote message of V2TimMessage type.
    onTap
    Click the vote callback. You can check group vote details in case of a public and real-name vote.

    Viewing Vote 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. Vote details data, obtained when TencentCloudChatVoteMessage is clicked.
    data
    TencentCloudChatVoteLogic type, obtained when TencentCloudChatVoteMessage is clicked.
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support