Skip to main content

Create Poll Screen

Introduction

The Create Poll Screen enables users to create and interact with polls. It supports creating polls of different types based on the community configurations set by the manager. Developers can further customize the behavior and UI using builder delegates.


1. LMChatCreatePollScreen Widget

File Location:
create_poll.dart

Class Declaration

class LMChatCreatePollScreen extends StatefulWidget {

State<LMChatCreatePollScreen> createState() => _LMChatCreatePollScreenState();
}

The LMChatCreatePollScreen widget displays the create poll screen, showing all the various options to create a poll.


2. LMChatCreatePollBuilderDelegate

File Location:
create_poll_builder.dart

Class Declaration

class LMChatCreatePollBuilderDelegate {
const LMChatCreatePollBuilderDelegate();
}

The LMChatCreatePollBuilderDelegate provides several methods to customize the UI and behavior of polls.

Methods in LMChatCreatePollBuilderDelegate

  1. scaffold
    Definition: Builds the scaffold for the poll view.
    Purpose: Customizes the primary structure of the poll interface.

    Usage Example:


    Widget scaffold({PreferredSizeWidget? appBar, Widget? body}) {
    return Scaffold(appBar: appBar, body: body);
    }
  2. userTileBuilder
    Definition: Builds the user tile for displaying user information.
    Purpose: Customizes how user tiles are displayed in the poll creation screen.

    Usage Example:


    Widget userTileBuilder(BuildContext context, LMChatUserTile userTile) {
    return userTile;
    }
  3. pollOptionTileBuilder
    Definition: Builds the poll option tile.
    Purpose: Customizes how poll options are displayed.

    Usage Example:


    Widget pollOptionTileBuilder(BuildContext context, LMChatOptionTile pollOption, int index,) {
    return pollOption;
    }

Remaining Methods

Explore the full list of methods here.


3. LMChatPollSetting

File Location:
setting.dart

class LMChatPollSetting {
const LMChatPollSetting();
}
  • Purpose: Provides settings for managing poll behavior, such as multi-select options.

4. LMChatPollStyle

File Location:
style.dart

class LMChatPollStyle {
const LMChatPollStyle();
}
  • Purpose: Defines the visual appearance of polls, such as colors and font styles.

5. LMChatPollConfig

File Location:
config.dart

Class Declaration

class LMChatPollConfig {
final LMChatPollResultBuilderDelegate pollResultBuilder;
final LMChatCreatePollBuilderDelegate createPollBuilder;
final LMChatPollSetting setting;
final LMChatPollStyle style;

const LMChatPollConfig({
this.pollResultBuilder = const LMChatPollResultBuilderDelegate(),
this.createPollBuilder = const LMChatCreatePollBuilderDelegate(),
this.setting = const LMChatPollSetting(),
this.style = const LMChatPollStyle(),
});
}

Usage Example: Injecting Custom Configuration

  1. Create a Custom Builder:

    class CustomCreatePollBuilder extends LMChatCreatePollBuilderDelegate {

    Widget voteCountTextBuilder(BuildContext context, int voteCount) {
    return Text('$voteCount votes', style: TextStyle(color: Colors.green));
    }
    }
  2. Pass Custom Style and Setting along with Builder:

    final customStyle = LMChatPollStyle();
    final customSetting = LMChatPollSetting();
  3. Inject the Custom Builder, Style, and Setting into the Config:

    final pollConfig = LMChatPollConfig(
    pollResultBuilder: CustomPollResultBuilder(),
    createPollBuilder: CustomCreatePollBuilder(),
    style: customStyle,
    setting: customSetting,
    );
  4. Initialize with Custom Config:

    LMChatCore.instance.initialize(
    config: LMChatConfig(
    pollConfig: pollConfig,
    ),
    );

6. Summary

The Create Poll Screen enables users to create polls, vote, and view poll results. Developers can customize the interface using LMChatCreatePollBuilderDelegate, and further control the behavior and appearance through LMChatPollConfig. This flexibility ensures the poll experience meets specific design and functional requirements.