搜索插件、代码仓与 APP 分类

flutter_fortune_wheel 封面
插件详情v1.3.2

flutter_fortune_wheel

使用旋转轮盘或运势条等小部件可视化(随机)选择过程。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1万
喜欢数
372
Pub 分数
115

安装插件

flutter pub add flutter_fortune_wheel

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Flutter Fortune Wheel 是一个可自定义的 widget 库,用于在 Flutter 应用中创建交互式旋转轮盘和幸运条。它使开发者能够可视化随机选择过程,非常适合游戏、奖励系统或抽奖机制。该包支持 Android、iOS、Web、macOS、Windows 和 Linux 多个平台,具有高度的通用性。通过流畅的动画和通过 pub 的简单集成,它通过动态视觉反馈增强用户参与度。开发者可以自定义扇区、颜色和旋转行为,以匹配其应用的设计。

适合场景

  • 游戏化用户奖励
  • 互动抽奖
  • 奖励选择界面
  • 引人入胜的入门体验
  • 随机内容显示
  • 忠诚度计划机制

主要特点

  • 平滑的旋转动画
  • 可自定义的轮盘扇区
  • 对多平台的支持
  • 与 pub 的轻松集成
  • 可配置的旋转持续时间和速度
  • 旋转完成时的事件回调

适合对象

  • 游戏开发者
  • 寻求交互性的应用设计师
  • 带有奖励机制的营销应用
  • 带有随机测验的教育类应用
  • 以用户体验为中心的移动应用

使用建议

  • 需要仔细处理动画时序
  • 复杂设计可能需要性能优化
  • 有限的内置可访问性功能
  • 不适用于高频快速旋转
  • 最适合偶尔的交互事件
  • 依赖外部依赖项以实现完整功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Coverage Status

Flutter Fortune Wheel

This Flutter package includes wheel of fortune widgets, which allow you to visualize random selection processes. They are highly customizable and work across mobile, desktop and the web.

You can learn more about the wheel's implementation in this article and try an interactive demo here.

Quick Start

First install the package via pub.dev. Then import and use the FortuneWheel:

import 'package:flutter/material.dart';
import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart';
StreamController<int> controller = StreamController<int>();
FortuneWheel(
  selected: controller.stream,
  items: [
    FortuneItem(child: Text('Han Solo')),
    FortuneItem(child: Text('Yoda')),
    FortuneItem(child: Text('Obi-Wan Kenobi')),
  ],
)

Examples

The wheel of fortune is the most iconic visualization.

Unfortunately, a circular shape is not the best solution when vertical screen space is scarce. Therefore, the fortune bar, which is smaller in the vertical direction, is provided as an alternative. See below for an example:

import 'package:flutter/material.dart';
import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart';

StreamController<int> controller = StreamController<int>();
FortuneBar(
  selected: controller.stream,
  items: [
    FortuneItem(child: Text('Han Solo')),
    FortuneItem(child: Text('Yoda')),
    FortuneItem(child: Text('Obi-Wan Kenobi')),
  ],
)

Customization

Drag Behavior

By default, the fortune widgets react to touch and drag input. This behavior can be customized using the physics property, which expects an implementation of the PanPhysics class. If you want to disable dragging, simply pass an instance of NoPanPhysics.

For the FortuneWheel, CircularPanPhysics is recommended, while the FortuneBar uses DirectionalPanPhysics.horizontal by default. If none of the available implementations, suit your needs, you can always implement a subclass of PanPhysics.

The callback passed to onFling is called when the pan physics detects a fling gesture. This gives you the opportunity to select a new random item.

StreamController<int> controller = StreamController<int>();
FortuneWheel(
  // changing the return animation when the user stops dragging
  physics: CircularPanPhysics(
    duration: Duration(seconds: 1),
    curve: Curves.decelerate,
  ),
  onFling: () {
    controller.add(1);
  }
  selected: controller.stream,
  items: [
    FortuneItem(child: Text('Han Solo')),
    FortuneItem(child: Text('Yoda')),
    FortuneItem(child: Text('Obi-Wan Kenobi')),
  ],
)
Item Styling

FortuneItems can be styled individually using their style property. Styling a FortuneWidget's items according to a common logic is achieved by passing a StyleStrategy. By default, the FortuneWheel uses the AlternatingStyleStrategy and the FortuneBar uses the UniformStyleStrategy. As with drag behavior, you can pass custom implementations to the styleStrategy property.

// styling FortuneItems individually
FortuneWheel(
  selected: Stream.value(0),
  items: [
    FortuneItem(
      child: Text('A'),
      style: FortuneItemStyle(
        color: Colors.red, // <-- custom circle slice fill color
        borderColor: Colors.green, // <-- custom circle slice stroke color
        borderWidth: 3, // <-- custom circle slice stroke width
      ),
    ),
    FortuneItem(child: Text('B')),
  ],
)

// common styling for all items of a FortuneWidget
FortuneBar(
  // using alternating item styles on a fortune bar
  styleStrategy: AlternatingStyleStrategy(),
  selected: Stream.value(0),
  items: [
    FortuneItem(child: Text('Han Solo')),
    FortuneItem(child: Text('Yoda')),
    FortuneItem(child: Text('Obi-Wan Kenobi')),
  ],
)
Indicator Styling

The position indicators can be customized by passing a list of FortuneIndicators to FortuneWidget.indicators. By default, the FortuneWheel uses a TriangleIndicator and the FortuneBar uses a RectangleIndicator. You may either pass styled versions of these existing widgets or create your own implementations, since indicators can be any kind of widget. Here is an example of using a customized indicator:

FortuneWheel(
  selected: Stream.value(0),
  indicators: <FortuneIndicator>[
    FortuneIndicator(
      alignment: Alignment.bottomCenter, // <-- changing the position of the indicator
      child: TriangleIndicator(
        color: Colors.green, // <-- changing the color of the indicator
        width: 20.0, // <-- changing the width of the indicator
        height: 20.0, // <-- changing the height of the indicator
        elevation: 0, // <-- changing the elevation of the indicator
      ),
    ),
  ],
  items: [
    FortuneItem(child: Text('A'))
    FortuneItem(child: Text('B')),
  ],
)

Contributions

Contributions are much appreciated.

If you have any ideas for alternative visualizations, feel free to open a pull request or raise an issue. The same holds for any requests regarding existing widgets.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目