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.

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';

FortuneWheel(
  selected: 0,
  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';

FortuneBar(
  selected: 0,
  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 behavior and slowly return to their initial state upon release. 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.

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

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.

Libraries

flutter_fortune_wheel
Visualize random selections with Flutter widgets like the wheel of fortune. [...]