Polls

Stream Chat’s Flutter SDK includes the capability to create polls within your chat application. Polls are an effective tool for enhancing user interaction and engagement, providing a dynamic way to gather opinions and feedback.

Polls on Flutter are available since version 9.0.0.

Polls are disabled by default. In order to enable this feature, you need to go to the Stream dashboard for your app, and enable the “Polls” flag for your channel type.

Screenshot showing how to enable polls

As soon as you do that, an additional “Polls” icon would be shown in the attachment picker in the default composer implementation in the SDK.

Screenshot showing polls icon in the composer

Poll Creator

When you tap the “Polls” icon, a new screen for creating polls would be shown. On this screen, you can configure the poll title, the options, as well as several other settings, such as the maximum number of votes, whether the poll is anonymous and if it allows comments.

Screenshot showing create poll view

You can also set various configuration used to validate while creating the poll. In order to do that, you need to provide your own PollConfig.

const pollConfig = PollConfig(
  nameRange: (min: 1, max: 80),
  optionsRange: (min: 1, max: 10),
  allowDuplicateOptions: false,
  allowedVotesRange: (min: 2, max: 10),
);

StreamMessageInput(
  ...,
  pollConfig: pollConfig,
);

Override Poll Creator Screen

You can customize the poll creation screen by overriding the poll-creator option in your StreamAttachmentsPicker. This allows you to tailor the appearance and behavior of the poll creation screen to better fit your application’s needs and user experience expectations.

showStreamAttachmentPickerModalBottomSheet(
  context: context,
  customOptions: [
    // Make sure to set the key and supportedTypes to 'poll-creator' and [AttachmentPickerType.poll]
    // to override the default poll creation screen.
    AttachmentPickerOption(
      key: 'poll-creator',
      icon: StreamSvgIcon.polls().toIconThemeSvgIcon(),
      supportedTypes: [AttachmentPickerType.poll],
      optionViewBuilder: (context, controller) {
        // Return your custom widget here
      },
    ),
  ],
);

Poll Interactor

Poll Interactor

The StreamPollInteractor displays the poll question and answer options, distinguishing between the poll owner and other users. It allows user interaction, shows real-time vote counts and participants, and displays the question title, answer items, and additional option buttons.

It is displayed as an item of the MessageListView similar to other messages and attachments.

© Getstream.io, Inc. All Rights Reserved.