搜尋套件、儲存庫與 APP 分類

套件詳情v1.1.0

flutter_spinning_wheel

一個可自訂的 widget,可在 Flutter 中用作旋轉輪。

近 30 天下載
42
喜歡數
89
Pub 分數
40

安裝套件

flutter pub add flutter_spinning_wheel

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個可自訂的 Flutter 小部件,專為建立互動式旋轉輪盤而設計,非常適合遊戲、獎勵和抽獎機制。它允許開發者定義具有自訂標籤、顏色和動畫的區段。輪盤支援平滑旋轉、可設定速度,並在完成時觸發事件回呼。以效能與易用性為設計核心,能順暢整合至 Flutter 應用中。適用於遊戲化應用中的沉浸式使用者體驗。

適用情境

  • 遊戲化使用者介面
  • 抽獎或彩券系統
  • 互動產品示範
  • 基於獎勵的應用程式功能
  • 隨機選擇的教育測驗

主要特色

  • 可自訂的區段設計
  • 平滑動畫控制
  • 可設定的旋轉速度與持續時間
  • 停止時的事件回調
  • 支援動態段更新
  • 與 Flutter UI 的輕鬆整合

適合對象

  • 遊戲開發人員建構應用程式
  • 設計用於創建互動式獎勵的設計師
  • 實施遊戲化功能的團隊
  • 教育類應用開發者
  • 具有互動元素的行銷活動

使用建議

  • 需要手動處理旋轉邏輯
  • 有限的內建可存取性功能
  • 所有平台皆無內建觸控手勢支援
  • 效能可能會因段落過多而有所變化
  • 未針對高頻率旋轉進行優化

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。