Tencent / Tencent/tdesign-flutter

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

Open
#949 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
1.2k
Forks
182
Avg merge
2d 2h
Merged PRs (30d)
88

Description

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

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

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the TDPicker.showDatePicker entry point and reproduce the provided example with dateStart, dateEnd, initialDate, and useSecond set to false. Trace how the picker applies the lower bound across year, month, day, hour, and minute, then verify that a date after dateStart permits earlier hours and minutes while respecting the complete range.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.