flutter_my_picker 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

flutter_my_picker #

GitHub GitHub stars

适用于flutter的有关日期和时间的选择器,支持年份(showYearPicker)、月份(showMonthPicker)、日期(showDatePicker)、时间(showTimePicker)、日期时间(showDateTimePicker)等。

支持的平台

  • Android
  • IOS

image

使用方法 #

依赖安装 #

  • 已发布到pub,可直接使用版本号进行下载
dependencies:
  ...
  flutter_my_picker: ^1.0.3

如果你想自己发布包,但是发布的时候报错,可以看这里发布教程

使用案例 #

导入 flutter_my_picker.dart;

import 'package:flutter_my_picker/flutter_my_picker.dart';

// 日期操作,需要时引入
import 'package:flutter_my_picker/common/date.dart';

年份选择器

_change(formatString) {
  return (_date) {
    setState(() {
      date = _date;
      dateStr = MyDate.format(formatString, _date);
    });
  };
}

MyPicker.showPicker(
  context: context,
  current: date,
  mode: MyPickerMode.year,
  onChange: _change('yyyy'),
);

// MyPicker.showYearPicker 效果一样,参数同上,不需要mode参数

月份选择器

MyPicker.showPicker(
  context: context,
  current: date,
  mode: MyPickerMode.month,
  onChange: _change('yyyy-MM'),
);

// MyPicker.showMonthPicker 效果一样,参数同上,不需要mode参数

日期选择器

MyPicker.showPicker(
  context: context,
  current: date,
  mode: MyPickerMode.date,
  onChange: _change('yyyy-MM-dd'),
);

// MyPicker.showDatePicker 效果一样,参数同上,不需要mode参数

时间选择器

MyPicker.showPicker(
  context: context,
  current: date,
  mode: MyPickerMode.time,
  onChange: _change('HH:mm'),
);

// MyPicker.showTimePicker 效果一样,参数同上,不需要mode参数

日期时间选择器

MyPicker.showPicker(
  context: context,
  current: date,
  mode: MyPickerMode.dateTime,
  onChange: _change('yyyy-MM-dd HH:mm'),
);

// MyPicker.showDateTimePicker 效果一样,参数同上,不需要mode参数

调用 MyPicker.showPicker 方法调起相关选择器,目前的参数有

API #

MyPicker.showPicker所需要的的参数:

// 调用 showModalBottomSheet 所需
BuildContext context;

// 当前选中的时间,字符串和DateTime类型皆可,内部做了解析,mode 为 time 时, 可直接传入 '20:12' 的字符串
final dynamic current;
/// 开始时间,不传时表示不限制,mode 为 time 时, 可直接传入 '20:12' 的字符串
final dynamic start;
/// 结束时间,不传时表示不限制,mode 为 time 时, 可直接传入 '20:12' 的字符串
final dynamic end;

// 选中时间结束之后的回调,当滚动未结束时关闭弹窗就不会触发
//typedef DateChangedCallback(DateTime time)
final DateChangedCallback onChange;

// 点击确认按钮之后的回调
//typedef DateChangedCallback(DateTime time)
final DateChangedCallback onConfirm;

// 点击取消按钮之后的回调
//typedef CancelCallback()
final CancelCallback onCancel;

// 选择器模式
/**
enum MyPickerMode {
  year,
  month,
  date,
  time,
  dateTime,
}
*/
final MyPickerMode mode;

// 选择器单行的高度,默认36
final double itemHeight;

/// 挤压系数,默认 1, 建议设置 1.45
final double squeeze;

/// 被选中的内容放大系数,默认 1, 建议设置 1.2
final double magnification;

/// 被选中的内容偏移,默认 0, 建议设置 0.2
final double offAxisFraction; 

1.0.4 #

  • fix picker start & end 未传入的问题

1.0.3 #

  • fix magnification 默认值
  • 支持 color 和 background

1.0.2 #

  • magnification
  • squeeze
  • offAxisFraction

1.0.0 #

  • 添加确认和取消按钮,添加onConfirm 和 onCancel 回调,通过 isShowHeader 属性控制是否显示,
  • 添加 start 和 end 属性设置开始和结束时间

0.0.3 #

  • 添加CHANGELOG.md

0.0.2 #

  • 优化文件内容,提高评分

0.0.1 #

  • 适用于flutter的有关日期和时间的选择器,支持年份(showYearPicker)、月份(showMonthPicker)、日期(showDatePicker)、时间(showTimePicker)、日期时间(showDateTimePicker)等。

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('使用案例'),
        ),
        body: DemoPage(),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_my_picker: ^1.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_my_picker/flutter_my_picker.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:flutter_my_picker/flutter_my_picker.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:flutter_my_picker/flutter_my_picker.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:flutter_my_picker/flutter_my_picker.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:flutter_my_picker/flutter_my_picker.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • flutter_my_picker that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
flutter 0.0.0
intl ^0.16.1 0.16.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
path 1.7.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test