搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案