英文:
How to limit the time in showTimePicker Flutter
问题
I need to set Time limit at TimePicker. like i need to set time picker in between 12pm to 6pm and another time i don't want to select from user.
In older version of flutter they provide allowedHours and allowedMinutes but in new version they hide that properties.
Older version code:-
showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
allowedHours: [8,9,10,11,12, 15,16,17],
allowedMinutes: [0,10,20,30,40,50],
displayDisabledValues: true
);
I want to set limit at TimePicker based on requirement. Is there any another way to set it. like any Property or any third party package?
英文:
I need to set Time limit at TimePicker. like i need to set time picker in between 12pm to 6pm and another time i don't want to select from user.
In older version of flutter they provide allowedHours and allowedMinutes but in new version they hide that properties.
Older version code:-
showTimePicker(
    context: context,
    initialTime: TimeOfDay.now(),
    allowedHours: [8,9,10,11,12, 15,16,17],
    allowedMinutes: [0,10,20,30,40,50],
    displayDisabledValues: true
);
I want to set limit at TimePicker based on requirement. Is there any another way to set it. like any Property or any third party package?
答案1
得分: 1
以下是翻译好的部分:
例如,我正在使用12 PM到2 PM。以下代码片段满足您的需求。
使用包名 time_range_picker: ^2.2.0。时间范围起始时间:
TimeOfDay(hour: 12, minute: 00),
end: TimeOfDay(hour: 02, minute: 00)
实现:
return Scaffold(
  body: Container(
    margin: EdgeInsets.only(top: 100),
    child: MaterialButton(
      onPressed: () async {
        TimeRange result = await showTimeRangePicker(
          context: context,
          start: TimeOfDay(hour: 12, minute: 00),
          end: TimeOfDay(hour: 02, minute: 00)
        );
        print("result " + result.toString());
      },
      child: Container(color: Colors.red, child: Text("显示时间选择器")),
    ),
  ),
);
英文:
For example I am using 12 pm to 2 PM. Below snippet meet with your purpose.
Use a packager name time_range_picker: ^2.2.0. Time range start:
    TimeOfDay(hour: 12, minute: 00),
                      end: TimeOfDay(hour: 02, minute: 00)
Implementation :
   return Scaffold(
          body: Container(
            margin: EdgeInsets.only(top: 100),
            child: MaterialButton(
              onPressed: () async {
                TimeRange result = await showTimeRangePicker(
                  context: context,
                  start: TimeOfDay(hour: 12, minute: 00),
                  end: TimeOfDay(hour: 02, minute: 00)
                );
                print("result " + result.toString());
              },
              child: Container(color: Colors.red, child: Text("Show Time Picker")),
            ),
          ),
        );  
package link : time_range_picker: ^2.2.0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论