搜索插件、代码仓与 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:.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。