Skip to main content

Create Poll Screen

Introduction

The Create Poll Screen (LMFeedCreatePollScreen) serves as the interface for creating polls. It provides customization options through builders, settings, and styles to meet specific design and functional requirements.


1. LMFeedCreatePollScreen Widget

File Location:
create_poll_screen.dart

Class Declaration

class LMFeedCreatePollScreen extends StatefulWidget {
/// A screen widget that facilitates the creation of a new poll.
const LMFeedCreatePollScreen({
super.key,
this.attachmentMeta,
this.appBarBuilder,
this.pollQuestionStyle,
this.optionStyle,
this.advancedButtonBuilder,
this.postButtonBuilder,
this.addOptionButtonBuilder,
});


State<LMFeedCreatePollScreen> createState() => _LMFeedCreatePollScreenState();
}

Key Parameters

  1. key (Key?, optional): A key to uniquely identify the widget.
  2. attachmentMeta (LMAttachmentMetaViewData?, optional): Metadata to prefill the poll data.
  3. appBarBuilder (LMFeedAppBarBuilder?, optional): Custom builder for the app bar.
  4. pollQuestionStyle (LMFeedTextFieldStyle?, optional): Style for the poll question.
  5. optionStyle (LMFeedTextFieldStyle?, optional): Style for the poll options.

For the complete source code, refer to the GitHub link.


2. LMFeedPollBuilderDelegate

File Location:
builder.dart

Class Declaration

class LMFeedPollBuilderDelegate extends LMFeedWidgetBuilderDelegate {
const LMFeedPollBuilderDelegate();
}

The LMFeedPollBuilderDelegate allows developers to customize various aspects of the poll screen, such as dialogs, input fields, and poll options.

Methods in LMFeedPollBuilderDelegate

  1. pollOptionBuilder
    Definition: Builds the widget for poll options.
    Purpose: Customizes the appearance and behavior of poll options.

    Usage Example:


    Widget pollOptionBuilder(BuildContext context, String option) {
    return Text(option);
    }
  2. submitButtonBuilder
    Definition: Builds the submit button for the poll screen.
    Purpose: Customizes the appearance and functionality of the submit button.

    Usage Example:


    Widget submitButtonBuilder(BuildContext context) {
    return ElevatedButton(
    onPressed: () => submitPoll(),
    child: Text('Submit Poll'),
    );
    }
  3. discardDialogBuilder
    Definition: Builds the dialog widget displayed when users discard the poll creation process.
    Purpose: Allows customization of the discard dialog.

    Usage Example:


    Widget discardDialogBuilder(BuildContext context) {
    return AlertDialog(
    title: Text('Discard Changes?'),
    actions: [
    TextButton(
    onPressed: () => Navigator.pop(context, true),
    child: Text('Yes'),
    ),
    TextButton(
    onPressed: () => Navigator.pop(context, false),
    child: Text('No'),
    ),
    ],
    );
    }

Remaining Methods

Explore the complete list of methods here.


3. LMFeedPollSetting

File Location:
settings.dart

class LMFeedPollSetting {
const LMFeedPollSetting();
}
  • Purpose: Provides configuration settings for the Create Poll Screen. No additional fields or methods are currently defined.

4. LMFeedPollStyle

File Location:
style.dart

class LMFeedPollStyle {
const LMFeedPollStyle();
}
  • Purpose: Defines styling options for the Create Poll Screen. No fields or methods are currently defined.

5. LMFeedPollConfig

File Location:
config.dart

Class Declaration

class LMFeedPollConfig {
final LMFeedPollBuilderDelegate builder;
final LMFeedPollSetting setting;
final LMFeedPollStyle style;

const LMFeedPollConfig({
this.builder = const LMFeedPollBuilderDelegate(),
this.setting = const LMFeedPollSetting(),
this.style = const LMFeedPollStyle(),
});
}

Usage Example: Injecting Custom Configuration

  1. Create a Custom Builder:

    class CustomPollBuilder extends LMFeedPollBuilderDelegate {

    Widget submitButtonBuilder(BuildContext context) {
    return ElevatedButton(
    onPressed: () => submitPoll(),
    child: Text('Custom Submit'),
    );
    }
    }
  2. Pass Custom Style or Setting along with Builder:

    final customStyle = LMFeedPollStyle();
    final customSetting = LMFeedPollSetting();
  3. Inject the Custom Builder, Style, or Setting into the Config:

    final pollConfig = LMFeedPollConfig(
    builder: CustomPollBuilder(),
    setting: customSetting,
    style: customStyle,
    );
  4. Initialize with Custom Config:

    LMFeedCore.instance.initialize(
    config: LMFeedConfig(
    pollConfig: pollConfig,
    ),
    );

6. Summary

The Create Poll Screen provides a user interface for creating polls. Developers can customize components like poll options, dialogs, and submit buttons using the LMFeedPollBuilderDelegate. Configuration options are encapsulated in LMFeedPollConfig, allowing seamless integration of customizations tailored to specific design and functional requirements.