Flutter 投票

Flutter 可自定义的投票。简单、易用且高度可定制。

pub.dev 上的 Flutter 投票

入门

在您的 flutter 项目的 pubspec.yaml 文件中,添加以下依赖项

dependencies:
  ...
  flutter_polls: ^0.0.1

导入它

import 'package:flutter_polls/flutter_polls.dart';

示例

Flutter Poll

FlutterPolls(
    pollId: '1',
    onVoted: (PollOption pollOption, int newTotalVotes) {
      print('Voted: ${pollOption.id}');
    },
    pollOptionsSplashColor: Colors.white(),
    votedProgressColor: Colors.greyDark().withOpacity(0.3),
    votedBackgroundColor: Colors.grey().withOpacity(0.2),
    votesTextStyle: themeData.textTheme.subtitle1,
    votedPercentageTextStyle:
        themeData.textTheme.headline4?.copyWith(
    color: Colors.black(),
    ),
    votedCheckmark: Icon(
        Icons.circle_check,
        color: AppColors.black(),
        height: 18,
        width: 18,
    ),
    pollTitle: Align(
    alignment: Alignment.centerLeft,
    child: AutoSizeText(
        poll['title'],
        style: TextStyle(
            fontSize: 20,
        ),
    ),
    pollOptions: poll['options'].map(
    (option) {
        return PollOption(
        id: option['id'],
        title: AutoSizeText(
            option['title'],
            style: tTextStyle(
            fontSize: 20,
        ),
        ),
        votes: option['votes'],
        );
    },
    ).toList(),
    metaWidget: Row(
    children: [
        const SizedBox(width: 6),
        AutoSizeText(
        '•',
        style: TextStyle(
            fontSize: 20,
        ),
        ),
        const SizedBox(
        width: 6,
        ),
        AutoSizeText(
        '2 weeks left',
        style: TextStyle(
            fontSize: 20,
        ),
        ),
    ],
    ),
),

参数

参数 类型 描述
pollId 字符串 投票 ID。
hasVoted 布尔值 用户是否已投票。
userVotedOptionId 整数 用户投票的选项 ID。如果用户未投票,则此项将为 null。
onVoted void Function(PollOption pollOption, int newTotalVotes) 用户投票时的回调。
pollTitle Widget 投票标题。可以是任何小部件。
pollOptions 列表 投票选项。每个项目都是一个具有以下键的映射:id、title、votes。
heightBetweenTitleAndOptions 双精度 投票标题和投票选项之间的高度。
heightBetweenOptions 双精度 投票选项之间的高度。
votesText 字符串 投票文本。可以是“Votes”、“Votos”、“Ibo”或任何语言。如果未指定,则默认为“Votes”。
votesTextStyle TextStyle 投票文本的样式。
metaWidget Widget 元数据小部件。可以是任何小部件。
createdBy 字符串 投票创建者。
userToVote 字符串 要投票的用户。
pollStartDate DateTime(日期时间) 投票开始日期。
pollEndDate DateTime(日期时间) 投票结束日期。
pollOptionsHeight 双精度 投票选项的高度。
pollOptionsWidth 双精度 投票选项的宽度。
pollOptionsBorderRadius BorderRadius 投票选项的边框半径。
pollOptionsBorder BoxBorder 投票选项的边框。
pollOptionsFillColor 颜色 投票选项的填充颜色。
pollOptionsSplashColor 颜色 投票选项的点击效果颜色。
votedPollOptionsRadius Radius 已投票的投票选项的边框半径。
votedBackgroundColor 颜色 已投票的投票选项的背景颜色。
votedProgressColor 颜色 已投票的投票选项的进度颜色。
votedCheckmark Widget 已投票的投票选项的复选标记。
votedPercentageTextStyle TextStyle 已投票的投票选项的百分比文本样式。
votedAnimationDuration 整数 已投票的投票选项的动画持续时间。

GitHub

查看 Github