搜索插件、代码仓与 APP 分类

duration_picker 封面
插件详情v2.0.0

duration_picker

一个可选择小时和分钟的时间选择器小部件。源自 flutter_duration_picker。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1万
喜欢数
126
Pub 分数
160

安装插件

flutter pub add duration_picker

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于通过小时和分钟选择时长的 Flutter 小部件,源自 flutter_duration_picker。它为用户提供了简洁直观的界面来选择时间间隔,非常适合用于计时器、任务时长或预约时长等设置。该选择器支持所有主要平台,包括移动设备、网页和桌面端。设计上注重简洁性和一致性,可无缝集成到需要时长输入的应用中,无需复杂的设置。

适合场景

  • 设置计时器持续时间
  • 配置任务长度偏好
  • 安排预约时长
  • 输入锻炼会话时间
  • 自定义播放时长
  • 定义延迟间隔

主要特点

  • 选择小时和分钟
  • 跨平台兼容性
  • 简单集成
  • 干净的UI设计
  • 分支并保持更新
  • 支持所有 Flutter 平台

适合对象

  • 需要时间间隔选择的应用
  • 生产力或健身应用
  • 日历或调度工具
  • 计时器或提醒功能
  • 寻求轻量级持续时间选择器的开发者

使用建议

  • 仅限小时和分钟
  • 不支持秒
  • 需要手动处理持续时间值
  • 不适用于长时间持续使用
  • 依赖于分叉仓库的稳定性
  • 无内置验证

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Duration Picker for flutter

Fork from flutter_duration_picker. https://github.com/cdharris/flutter_duration_picker

A little widget for picking durations. Heavily inspired from the Material Design time picker widget.

How to setup localization

In order to support other languages, developers need to configure localization settings like the settings for the time picker. Example for english and korean:

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Duration Picker Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      localizationsDelegates: [
        DurationPickerLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [Locale('en'), Locale('ko')],
      home: const MyHomePage(title: 'Duration Picker Demo'),
    );
  }
}

How to add more languages

  1. Add a localizations class in localizataions dir.
class DurationPickerLocalizationsKo extends DurationPickerLocalizations {
  @override
  String get baseUnitHour => '시간';

  @override
  String get baseUnitMillisecond => '밀리초';

  ...
}

The class should extend DurationPickerLocalizations. This makes it easy to write everything you should write.

  1. Add the language code to the supportedLocales array in _DurationPickerLocalizationDelegate.
class _DurationPickerLocalizationDelegate
    extends LocalizationsDelegate<DurationPickerLocalizations> {
  const _DurationPickerLocalizationDelegate();

  static const supportedLocales = ['en', 'ko'];

  ...

}
  1. Return a DurationPickerLocalizations implementation as locale at load method in _DurationPickerLocalizationDelegate.
@override
  Future<DurationPickerLocalizations> load(Locale locale) async {
    switch (locale.languageCode) {
      case 'ko':
        return DurationPickerLocalizationsKo();
      default:
        return DurationPickerLocalizationsEn();
    }
  }

Example Usage:

dependencies:
  duration_picker: "^1.0.0"
import 'package:flutter/material.dart';
import 'package:duration_picker/duration_picker.dart';

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

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

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Duration _duration = Duration(hours: 0, minutes: 0);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(
                child: DurationPicker(
              duration: _duration,
              onChange: (val) {
                setState(() => _duration = val);
              },
            ))
          ],
        ),
      ),
      floatingActionButton: Builder(
          builder: (BuildContext context) => FloatingActionButton(
                onPressed: () async {
                  var resultingDuration = await showDurationPicker(
                    context: context,
                    initialTime: Duration(minutes: 30),
                  );
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                      content: Text('Chose duration: $resultingDuration')));
                },
                tooltip: 'Popup Duration Picker',
                child: Icon(Icons.add),
              )),
    );
  }
}

所属分类

源码仓库

使用此插件的项目