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

wheel_picker 封面
套件詳情v0.4.0

wheel_picker

一個使用輸入輪盤選擇值/時間的小部件。可自訂且輕量。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.2萬
喜歡數
83
Pub 分數
160

安裝套件

flutter pub add wheel_picker

套件介紹

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

一個輕量且可自定的 Flutter 小部件,實作基於輪盤的選擇器以選擇值或時間。受原生旋轉器啟發,它在各平台上提供流暢滾動和直覺互動。非常適合需要選擇日期、時間或離散值的表單。該套件設計高效且易於整合,支援 Android、iOS、Web、macOS、Windows 與 Linux。它提供乾淨的 API 來自訂外觀與行為,而不會增加顯著負荷。

適用情境

  • 具有離散選項的表單輸入
  • 時間選擇介面
  • 自定數字或下拉選擇器
  • 帶視覺反饋的資料輸入
  • 多輪值選擇

主要特色

  • 平滑滾動動畫
  • 跨平台相容性
  • 可自訂外觀
  • 輕量級效能
  • 與表單欄位的輕鬆整合
  • 可設定的項目間距與大小

適合對象

  • 開發表單密集型應用的開發者
  • 需要原生樣式選擇器的UI設計師
  • 需要時間或數值選擇的應用程式
  • 重視最小化套件大小的專案
  • 針對多個平台的團隊

使用建議

  • 有限的內建驗證
  • 無自動鍵盤整合
  • 需要手動處理選擇事件
  • 未針對非常大的資料集進行優化
  • 可能需要額外的樣式以支援深色模式

原始 README

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

Wheel Picker

A superset version of original ListWheelScrollView for easily creating wheel scroll input.

Flutter Pub

Left Gif Right Gif

Key Features

  • Item Selection: Retrieve the selected item index effortlessly.
  • Highlight Selection: Highlight selected items with a color shader.
  • Tap Navigation: Enable tap scrolls.
  • Horizontal Scroll Direction: Horizontal wheel scroll view.
  • Styling Flexibility: Customize wheel appearance with WheelPickerStyle.
  • Precise Control: Manage and synchronize WheelPicker widgets with a WheelPickerController.
  • Mounting Controllers: Easily integrate and shift multiple controllers.

Installing

Add it to your pubspec.yaml file:

dependencies:
  wheel_picker: ^0.3.0

Install packages from the command line:

flutter packages get

Usage

To use package, just import package import 'package:wheel_picker/wheel_picker.dart';

Example

Here's a quick example to get you started:

const daysOfWeek = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
return WheelPicker(
  itemCount: 7,
  builder: (context, index) => Text(daysOfWeek[index]),
  selectedIndexColor: Colors.orange,
  looping: false,
);
Basic (Left Gif)

For more control, you can attach a controller and adjust it to your liking:

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:wheel_picker/wheel_picker.dart';

class WheelPickerExample extends StatelessWidget {
  const WheelPickerExample({super.key});

  @override
  Widget build(BuildContext context) {
    final secondsWheel = WheelPickerController(itemCount: 10);
    const textStyle = TextStyle(fontSize: 32.0, height: 1.5);

    Timer.periodic(const Duration(seconds: 1), (_) => secondsWheel.shiftDown());

    return WheelPicker(
      builder: (context, index) => Text("$index", style: textStyle),
      controller: secondsWheel,
      selectedIndexColor: Colors.blue,
      onIndexChanged: (index, interactionType) => print("On index $index"),
      style: WheelPickerStyle(
        itemExtent: textStyle.fontSize! * textStyle.height!, // Text height
        squeeze: 1.25,
        diameterRatio: .8,
        surroundingOpacity: .25,
        magnification: 1.2,
      ),
    );
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Example',
      home: Scaffold(
        body: Center(
          child: WheelPickerExample(),
        ),
      ),
    );
  }
}

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

Note: This works for this short example but don't forget to manually dispose controllers you initialize youself.

Advanced (Right Gif)

For more advanced usage, you can also mount controllers, making them shift each other. See example.

Example: Listening for the scroll end event
const daysOfWeek = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];

return NotificationListener(
  onNotification: (notification) {
    if (notification is ScrollEndNotification) {
      print('User has ended scrolling');
    }
    return false;
  },
  child: WheelPicker(
    itemCount: 7,
    builder: (context, index) => Text(daysOfWeek[index]),
    selectedIndexColor: Colors.orange,
    looping: false,
  ),
);


Feel free to share your feedback, suggestions, or contribute to this package :handshake:.

If you like this package, consider supporting it by giving it a star on GitHub and a like on pub.dev :heart:.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。