All Projects → kevlatus → flutter_fortune_wheel

kevlatus / flutter_fortune_wheel

Licence: MIT license
Visualize random selections with Flutter widgets like the wheel of fortune.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to flutter fortune wheel

this-is-your-life
An angular app character backstories based on the Xanathar's Guide to Everything 'This Is Your Life' tables.
Stars: ✭ 36 (-40%)
Mutual labels:  random
Fluent-Random-Picker
Fluent Random Picker is a nice, performant, fluent way to pick random values. Probabilities can be specified, values can be weighted.
Stars: ✭ 26 (-56.67%)
Mutual labels:  random
rocRAND
RAND library for HIP programming language
Stars: ✭ 68 (+13.33%)
Mutual labels:  random
rango
Random. Django. Rango. An introduction to using Python and Django to build a website.
Stars: ✭ 53 (-11.67%)
Mutual labels:  random
awesome-randomizers
🎲 A curated list of awesome services for obtaining random results.
Stars: ✭ 36 (-40%)
Mutual labels:  random
order-id
Unique order id generator
Stars: ✭ 46 (-23.33%)
Mutual labels:  random
WeightedRandomSelector
Very fast C# class for weighted random picking.
Stars: ✭ 117 (+95%)
Mutual labels:  random
random
This is all my random garbage.
Stars: ✭ 23 (-61.67%)
Mutual labels:  random
sfmt-erlang
sfmt-erlang: SIMD-oriented Fast Mersenne Twister (SFMT) for Erlang
Stars: ✭ 70 (+16.67%)
Mutual labels:  random
Foodish
A Node.js/Express.js REST API to GET a random picture of food dishes.
Stars: ✭ 55 (-8.33%)
Mutual labels:  random
msp430-rng
Random (SLAA338) and pseudorandom (LCG) number generation.
Stars: ✭ 19 (-68.33%)
Mutual labels:  random
randomdata
TYPO3 extensions to generate new random data or replace existing data with random data
Stars: ✭ 14 (-76.67%)
Mutual labels:  random
faker
Random fake data and struct generator for Go.
Stars: ✭ 67 (+11.67%)
Mutual labels:  random
alokmenghrajani.github.com
Alok Menghrajani's Blog
Stars: ✭ 64 (+6.67%)
Mutual labels:  random
fortune500
Fortune 500 company lists since 1955 in CSV format, mostly parsed using Beautiful Soup
Stars: ✭ 78 (+30%)
Mutual labels:  fortune
jRand
A Java library to generate random data for all sorts of things. Java random data faker
Stars: ✭ 27 (-55%)
Mutual labels:  random
SDETools
Matlab Toolbox for the Numerical Solution of Stochastic Differential Equations
Stars: ✭ 80 (+33.33%)
Mutual labels:  random
RandLib
🚀 A library designed to facilitate work with probability, statistics and stochastic calculus
Stars: ✭ 64 (+6.67%)
Mutual labels:  random
fortunes
My personal collection of Fortune files
Stars: ✭ 20 (-66.67%)
Mutual labels:  fortune
prvhash
PRVHASH - Pseudo-Random-Value Hash. Hash functions, PRNG with unlimited period, randomness extractor. (Codename Gradilac/Градилак)
Stars: ✭ 194 (+223.33%)
Mutual labels:  random

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
      ),
    ),
  ],
  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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].