Poll Result Screen
Introduction
The Poll Result Screen enables users to create and interact with polls. It supports creating polls via a bottom sheet and displaying poll results. Developers can further customize the behavior and UI using builder delegates.
1. LMChatPollResultScreen
Widget
File Location:
poll_result.dart
Class Declaration
class LMChatPollResultScreen extends StatefulWidget {
State<LMChatPollResultScreen> createState() =>
_LMChatPollResultScreenState();
}
The LMChatPollResultScreen
widget displays the results of a poll, showing the poll options and the corresponding vote counts and users.
2. LMChatOptionTile
Widget
File Location:
create_poll.dart
Class Declaration
class LMChatOptionTile extends StatefulWidget {
State<LMChatOptionTile> createState() => _LMChatOptionTileState();
}
The LMChatOptionTile
widget represents individual poll options. It is used within the poll creation flow.
3. LMChatPollResultBuilderDelegate
File Location:
builder.dart
Class Declaration
class LMChatPollResultBuilderDelegate {
const LMChatPollResultBuilderDelegate();
}
The LMChatPollResultBuilderDelegate
provides several methods to customize the UI and behavior of polls.
Methods in LMChatPollResultBuilderDelegate
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);
}voteCountTextBuilder
Definition: Builds the vote count text for each poll option.
Purpose: Customizes the display of the vote counts.Usage Example:
Widget voteCountTextBuilder(BuildContext context, int voteCount) {
return Text('$voteCount votes');
}pollOptionTextBuilder
Definition: Builds the text for poll options.
Purpose: Customizes how poll options are displayed.Usage Example:
Widget pollOptionTextBuilder(BuildContext context, String option) {
return Text(option);
}
Remaining Methods
Explore the full list of methods here.
4. LMChatPollSetting
File Location:
setting.dart
class LMChatPollSetting {
const LMChatPollSetting();
}
- Purpose: Provides settings for managing poll behavior, such as multi-select options.
5. LMChatPollStyle
File Location:
style.dart
class LMChatPollStyle {
const LMChatPollStyle();
}
- Purpose: Defines the visual appearance of polls, such as colors and font styles.
6. 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
Create a Custom Builder:
class CustomPollResultBuilder extends LMChatPollResultBuilderDelegate {
Widget voteCountTextBuilder(BuildContext context, int voteCount) {
return Text('$voteCount votes', style: TextStyle(color: Colors.green));
}
}Pass Custom Style and Setting along with Builder:
final customStyle = LMChatPollStyle();
final customSetting = LMChatPollSetting();Inject the Custom Builder, Style, and Setting into the Config:
final pollConfig = LMChatPollConfig(
pollResultBuilder: CustomPollResultBuilder(),
createPollBuilder: CustomCreatePollBuilder(),
style: customStyle,
setting: customSetting,
);Initialize with Custom Config:
LMChatCore.instance.initialize(
config: LMChatConfig(
pollConfig: pollConfig,
),
);
7. Summary
The Poll Result Screen enables users to create polls, vote, and view poll results. Developers can customize the interface using LMChatPollResultBuilderDelegate
, and further control the behavior and appearance through LMChatPollConfig
. This flexibility ensures the poll experience meets specific design and functional requirements.