Skip to content

[TDPicker] showDatePicker中,即使日期的年月日在dateStart之后,时和分也无法选择小于dateStart的时分 #949

@shenjingfs

Description

@shenjingfs

tdesign-flutter 版本

0.2.7

重现链接

No response

重现步骤/代码

import 'package:flutter/material.dart';

import 'package:tdesign_flutter/tdesign_flutter.dart';

class TimePage extends StatefulWidget {
  const TimePage({super.key});

  @override
  State<TimePage> createState() => _TimePageState();
}

class _TimePageState extends State<TimePage> {
  DateTime? _date;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('时间'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              _date == null ? '请选择时间' : _date!.toString(),
              style: const TextStyle(fontSize: 20),
            ),
            const SizedBox(height: 16),
            FilledButton(
              onPressed: _pickTime,
              child: const Text('选择时间'),
            )
          ],
        ),
      ),
    );
  }

  void _pickTime() {
    final dateStart   = DateTime(2026, 1,  1,  19, 10, 11);
    final dateEnd     = DateTime(2026, 12, 31, 23, 59, 59);

    // final initialDate = DateTime(2026, 5,  2,  18, 1, 2);
    final initialDate = DateTime(2026, 5,  2,  20, 11, 12);

    TDPicker.showDatePicker(
      context,
      title: '选择时间',
      useYear: true,
      useMonth: true,
      useDay: true,
      useHour: true,
      useMinute: true,
      // useSecond: true,
      useSecond: false,
      dateStart: <int>[dateStart.year, dateStart.month, dateStart.day, dateStart.hour, dateStart.minute, dateStart.second],
      dateEnd: <int>[dateEnd.year, dateEnd.month, dateEnd.day, dateEnd.hour, dateEnd.minute, dateEnd.second],
      initialDate: <int>[initialDate.year, initialDate.month, initialDate.day, initialDate.hour, initialDate.minute, initialDate.second],
      onConfirm: (Map<String, int> selected) {
        setState(() {
          _date = DateTime(
            selected['year'] ?? initialDate.year,
            selected['month'] ?? initialDate.month,
            selected['day'] ?? initialDate.day,
            selected['hour'] ?? initialDate.hour,
            selected['minute'] ?? initialDate.minute,
            selected['second'] ?? initialDate.second,
          );
        });
        Navigator.of(context).pop();
      },
    );
  }
}

期望结果

No response

实际结果

如果initialDate的时分大于dateStart的时分,即使日期在dateStart之后,时和分也无法选择小于dateStart的时分

Flutter版本

Flutter(3.41.2)

设备与机型信息

Android(Redmi K50)

系统版本

Android 13

补充说明

  1. initialDate的时分大于dateStart的时分,然后单独useSecond设为false,时分最小只能设为19和10

    Screenrecorder-2026-05-26-15-05-55-930.mp4

  2. initialDate的时分小于等于dateStart的时分 final initialDate = DateTime(2026, 5, 2, 18, 1, 2);,然后单独useSecond设为false,正常

  3. initialDate的时分大于dateStart的时分秒,然后useXXX全设为true,初始显示时分秒只能设置到19:10:11,滚动时分秒后,分秒最小值正常,时最小还是19;滚动年月日后,全都正常。

    Screenrecorder-2026-05-26-15-11-53-494.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions