Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增pickerHeight、pickerItemCount参数,用于控制时间选择组件高度 #421

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tdesign-component/example/lib/page/td_calendar_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ Widget _buildSimple(BuildContext context) {
value: value,
height: size.height * 0.92,
useTimePicker: true,
// pickerHeight: 100,
// pickerItemCount: 2,
onCellClick: (value, type, tdate) {
print('onCellClick:$value');
},
Expand Down
23 changes: 18 additions & 5 deletions tdesign-component/lib/src/components/calendar/td_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class TDCalendar extends StatefulWidget {
this.timePickerModel,
this.monthTitleHeight = 22,
this.monthTitleBuilder,
this.pickerHeight = 178,
this.pickerItemCount = 3,
this.isTimeUnit = true,
}) : super(key: key);

/// 第一天从星期几开始,默认 0 = 周日
Expand Down Expand Up @@ -107,6 +110,15 @@ class TDCalendar extends StatefulWidget {
/// 月标题构建器
final Widget Function(BuildContext context, DateTime monthDate)? monthTitleBuilder;

/// 时间选择器List的视窗高度
final double? pickerHeight;

/// 选择器List视窗中item个数,pickerHeight / pickerItemCount即item高度
final int? pickerItemCount;

/// 是否显示时间单位
final bool? isTimeUnit;

List<DateTime>? get _value => value?.map((e) {
final date = DateTime.fromMillisecondsSinceEpoch(e);
return DateTime(date.year, date.month, date.day);
Expand Down Expand Up @@ -292,10 +304,11 @@ class _TDCalendarState extends State<TDCalendar> {
leftText: '',
rightText: '',
model: timePickerModel,
pickerHeight: 178,
pickerItemCount: 3,
onConfirm: (Map<String, int> selected) {},
onSelectedItemChanged: (wheelIndex,index) {
pickerHeight: widget.pickerHeight ?? 178,
pickerItemCount: widget.pickerItemCount ?? 3,
isTimeUnit: widget.isTimeUnit ?? true,
onConfirm: (selected) {},
onSelectedItemChanged: (wheelIndex, index) {
final time = _getValue(inherited?.selected.value ?? []);
inherited?.selected.value = time;
widget.onChange?.call(time);
Expand Down Expand Up @@ -330,7 +343,7 @@ class _TDCalendarState extends State<TDCalendar> {
return e + (milliseconds.getOrNull(index) ?? 0);
}).toList();
}

void _initValue() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
inherited?.selected.value = _getValue(widget.value ?? []);
Expand Down
Loading