All Projects → davidanaya → flutter-spinning-wheel

davidanaya / flutter-spinning-wheel

Licence: MIT license
A very customizable spinning wheel widget for Flutter.

Programming Languages

dart
5743 projects
objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to flutter-spinning-wheel

Tensorflow-binaries
Tensorflow GNU/Linux, MacOS binaries compiled with SSE4.1, SSE4.2 and AVX
Stars: ✭ 14 (-87.27%)
Mutual labels:  wheel
getwidget-docs
Get Widgets UI library docs.
Stars: ✭ 17 (-84.55%)
Mutual labels:  flutter-widget
flutter-app
Full Feature Todos Flutter Mobile app with fireStore integration.
Stars: ✭ 138 (+25.45%)
Mutual labels:  flutter-widget
Unity3D-Cars
A project built for a Renaissance Coders tutorial to introduce vehicle physics.
Stars: ✭ 60 (-45.45%)
Mutual labels:  wheel
trampolim
A modern Python build backend
Stars: ✭ 39 (-64.55%)
Mutual labels:  wheel
flutter date picker timeline
Gregorian and Jalali customizable date picker as a horizontal timeline
Stars: ✭ 29 (-73.64%)
Mutual labels:  flutter-widget
flutter spinbox
Material & Cupertino SpinBox for Flutter
Stars: ✭ 26 (-76.36%)
Mutual labels:  flutter-widget
check-wheel-contents
Check your wheels have the right contents
Stars: ✭ 131 (+19.09%)
Mutual labels:  wheel
car rental lite
A platform for car sharing where users can book any car that suits their needs and wants for their intended journey, from the closest hosts in the community.
Stars: ✭ 28 (-74.55%)
Mutual labels:  flutter-widget
SpinningWheelAndroid
Custom Spinning Wheel View for Android
Stars: ✭ 45 (-59.09%)
Mutual labels:  wheel
text-style-editor
Text style editor widget for flutter
Stars: ✭ 25 (-77.27%)
Mutual labels:  flutter-widget
flutter-tips
My collection of Flutter development tips
Stars: ✭ 36 (-67.27%)
Mutual labels:  flutter-widget
no-manylinux
Install this package to disable manylinux wheels when dowloading from pip.
Stars: ✭ 23 (-79.09%)
Mutual labels:  wheel
Knockdown-Flutter
Enough exercises to knockdown the fear of Flutter in you 👊
Stars: ✭ 33 (-70%)
Mutual labels:  flutter-widget
seo renderer
A Flutter Web Plugin to display Text Widget as Html for SEO purpose
Stars: ✭ 103 (-6.36%)
Mutual labels:  flutter-widget
barcode.flutter
barcode generate library for Flutter
Stars: ✭ 58 (-47.27%)
Mutual labels:  flutter-widget
installer
A low-level library for installing from a Python wheel distribution.
Stars: ✭ 72 (-34.55%)
Mutual labels:  wheel
embla-carousel-wheel-gestures
wheel interactions for Embla Carousel
Stars: ✭ 30 (-72.73%)
Mutual labels:  wheel
flutter ui stepper
A flutter challenge to create a stepper
Stars: ✭ 19 (-82.73%)
Mutual labels:  flutter-widget
ansible-role-admin-users
Ansible role to manage admin users, authorized keys and sudo access.
Stars: ✭ 18 (-83.64%)
Mutual labels:  wheel

flutter_spinning_wheel

Build Status License: MIT Pub

A customizable widget to use as a spinning wheel in Flutter.

Getting Started

Installation

Add

flutter_spinning_wheel : ^lastest_version

to your pubspec.yaml, and run

flutter packages get

in your project's root directory.

Basic Usage

Create a new project with command

flutter create myapp

Edit lib/main.dart like this:

import 'package:flutter/material.dart';

import 'package:flutter_circular_slider/flutter_circular_slider.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.blueGrey,
        body: Center(
          child: Container(child:
            SpinningWheel(
              Image.asset('assets/images/wheel-6-300.png'),
              width: 310,
              height: 310,
              dividers: 6,
              onEnd: _dividerController.add,
            ),
          ),
        ));
  }
}

You can replace the image with one of your preference.

Basic Game
Basic Wheel Game Wheel

Constructor

Parameter Default Description
image The image to be used as wheel.
dividers The number of divisions in the image. It's important that all divisions are equal.
height Height of the container that will display the wheel.
width Width of the container that will display the wheel.
initialSpinAngle 0.0 Initial rotation angle for the wheel, so the wheel could look initialy rotated.
spinResistance 0.5 From >0.0 to 1.0 will be used to calculate the speed and deceleration of the wheel.
canInteractWhileSpinning true If set to false, once the animation starts the user won't be able to stop it.
secondaryImage Secondary image that will be rendered on top of the wheel and won't be affected by the animation.
secondaryImageHeight Height for the secondary image.
secondaryImageWidth Width for the secondary image.
secondaryImageTop Used to fine tune the position of the secondary image. Otherwise it will be centered.
secondaryImageLeft Used to fine tune the position of the secondary image. Otherwise it will be centered.
onUpdate void onUpdate(int value) Callback function executed when the selected divider changes during the animation.
onEnd void onEnd(int value) Callback function executed when the animation stops.
shouldStartOrStop Stream to interact with the wheel, with double being pixelsPerSecond in axis y (default 8000)

Use Cases

Game

import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_spinning_wheel/flutter_spinning_wheel.dart';

void main() {
  SystemChrome.setEnabledSystemUIOverlays([]);
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final StreamController _dividerController = StreamController<int>();

  dispose() {
    _dividerController.close();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(backgroundColor: Color(0xffDDC3FF), elevation: 0.0),
      backgroundColor: Color(0xffDDC3FF),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SpinningWheel(
              Image.asset('assets/images/roulette-8-300.png'),
              width: 310,
              height: 310,
              initialSpinAngle: _generateRandomAngle(),
              spinResistance: 0.6,
              canInteractWhileSpinning: false,
              dividers: 8,
              onUpdate: _dividerController.add,
              onEnd: _dividerController.add,
              secondaryImage:
                  Image.asset('assets/images/roulette-center-300.png'),
              secondaryImageHeight: 110,
              secondaryImageWidth: 110,
            ),
            SizedBox(height: 30),
            StreamBuilder(
              stream: _dividerController.stream,
              builder: (context, snapshot) =>
                  snapshot.hasData ? RouletteScore(snapshot.data) : Container(),
            )
          ],
        ),
      ),
    );
  }

  double _generateRandomAngle() => Random().nextDouble() * pi * 2;
}

class RouletteScore extends StatelessWidget {
  final int selected;

  final Map<int, String> labels = {
    1: '1000\$',
    2: '400\$',
    3: '800\$',
    4: '7000\$',
    5: '5000\$',
    6: '300\$',
    7: '2000\$',
    8: '100\$',
  };

  RouletteScore(this.selected);

  @override
  Widget build(BuildContext context) {
    return Text('${labels[selected]}',
        style: TextStyle(fontStyle: FontStyle.italic, fontSize: 24.0));
  }
}

Game Wheel

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