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. LMChatCreatePollBottomSheet
Widget
File Location:
create_poll.dart
Class Declaration
class LMChatCreatePollBottomSheet extends StatefulWidget {
State<LMChatCreatePollBottomSheet> createState() =>
_LMChatCreatePollBottomSheetState();
}
This widget provides a bottom sheet interface for creating new polls, allowing users to input poll questions and options.
3. 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.
4. LMChatPollBuilderDelegate
File Location:
builder.dart
Class Declaration
class LMChatPollBuilderDelegate {
const LMChatPollBuilderDelegate();
}
The LMChatPollBuilderDelegate
provides several methods to customize the UI and behavior of polls.
Methods in LMChatPollBuilderDelegate
(3 out of X shown)
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.
5. LMChatPollSetting
File Location:
setting.dart
class LMChatPollSetting {
const LMChatPollSetting();
}
- Purpose: Provides settings for managing poll behavior, such as multi-select options.
6. LMChatPollStyle
File Location:
style.dart
class LMChatPollStyle {
const LMChatPollStyle();
}
- Purpose: Defines the visual appearance of polls, such as colors and font styles.
7. LMChatPollConfig
File Location:
config.dart
Class Declaration
class LMChatPollConfig {
final LMChatPollBuilderDelegate builder;
final LMChatPollSetting setting;
final LMChatPollStyle style;
const LMChatPollConfig({
this.builder = const LMChatPollBuilderDelegate(),
this.setting = const LMChatPollSetting(),
this.style = const LMChatPollStyle(),
});
}
Usage Example: Injecting Custom Configuration
Create a Custom Builder:
class CustomPollBuilder extends LMChatPollBuilderDelegate {
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(
builder: CustomPollBuilder(),
style: customStyle,
setting: customSetting,
);Initialize with Custom Config:
LMChatCore.instance.initialize(
config: LMChatConfig(
pollConfig: pollConfig,
),
);
8. Summary
The Poll Result Screen enables users to create polls, vote, and view poll results. Developers can customize the interface using LMChatPollBuilderDelegate
, and further control the behavior and appearance through LMChatPollConfig
. This flexibility ensures the poll experience meets specific design and functional requirements.