搜尋套件、儲存庫與 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),
              )),
    );
  }
}

所屬分類

原始碼儲存庫

使用此套件的專案