Polls

pub package

GitHub

ScreenShots

Voting Not Voted Yet Voted

Usage

Basic:

import 'package:better_polls/better_polls.dart';
Polls(
    children: [
      // This cannot be less than 2, else will throw an exception
      Polls.options(title: 'Cairo', value: option1),
      Polls.options(title: 'Mecca', value: option2),
      Polls.options(title: 'Denmark', value: option3),
      Polls.options(title: 'Maldives', value: option4),
    ],
    optionBarRadius: 24,
    borderWidth: 1,
    optionHeight: 40,
    question: const Padding(
      padding: EdgeInsets.only(bottom: 16.0),
      child: Text('What is your favorite place?'),
    ),
    currentUser: user,
    creatorID: creator,
    voteData: usersWhoVoted,
    userChoice: usersWhoVoted[user],
    onVoteBorderColor: Colors.deepPurple,
    voteCastedBorderColor: Colors.transparent,
    onVoteBackgroundColor: Colors.blue,
    leadingBackgroundColor: Colors.lightGreen,
    backgroundColor: Colors.white,
    onVote: (choice) {
      setState(() {
        usersWhoVoted[user] = choice;
      });
      if (choice == 1) {
        setState(() {
          option1 += 1.0;
        });
      }
      if (choice == 2) {
        setState(() {
          option2 += 1.0;
        });
      }
      if (choice == 3) {
        setState(() {
          option3 += 1.0;
        });
      }
      if (choice == 4) {
        setState(() {
          option4 += 1.0;
        });
      }
    },
  );

Poll View type

Polls(
  viewType: PollsType.creator
);
Polls(
viewType: PollsType.voter
);
Polls(
viewType: PollsType.readOnly
);

Why we forked the original polls package

We initially forked the package to update the package for Flutter 3, after the orignal package was not updated for months. After diving into the code, we noticed many design issues and it gave us even more of a reason to fork the package. Our version now includes various improvements on structure and overall code cleanliness. Some of the enhancements, include reduction in line count from 1500 to 500, remove redundant code, add ability to add unlimited polls, and overall maintainability improvements.

Libraries

better_polls