flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.2k stars 27.49k forks source link

[Proposal]Add parameter to display only numbers in CupertinoTimePicker #100178

Open evandrmb opened 2 years ago

evandrmb commented 2 years ago

Use case

By default, CupertinoTimePicker displays the number and what it represents like 1 hour 24 min.. But if we take a closer look at Apple's native Clock app, we can see that the TimePicker displayed there is built only with numbers

image

Proposal

I believe a boolean parameter could be added in order to either display or hide the text.

maheshj01 commented 2 years ago

Hi @evandrmb, Thanks for filing the issue. That looks like a valid proposal to me, This is how flutter's CupertinoTimePicker looks with CupertinoTimerPickerMode.hms Probably we should have another enum to hide the text.

image
code sample ```dart import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return const MaterialApp( title: 'Flutter Demo', home: HomePage(), ); } } class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { Duration initialtimer = Duration.zero; @override Widget build(BuildContext context) { return Scaffold( body: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ CupertinoTimerPicker( mode: CupertinoTimerPickerMode.hms, minuteInterval: 1, secondInterval: 1, initialTimerDuration: initialtimer, onTimerDurationChanged: (Duration changedtimer) { setState(() { initialtimer = changedtimer; }); }, ), ], )); } } ```
lpbas commented 11 months ago

Any updates on this feature request?

Hiding the labels would also be useful in use cases where we want to use the CupertinoTimePicker to pick a time, e.g. for the start time of a calendar event in a calendar app, where the current implementation that has hours and minutes (referring to the Duration, makes this use case rather confusing for the users.

A simple addition to the CupertinoTimerPickerMode enum would be fine, as we can keep working with Durations and use the following extensions to convert the Duration to TimeOfDay for the use case of i've mentioned above:

extension ExtTimeOfDay on TimeOfDay {
  Duration get asDuration {
    return Duration(hours: hour, minutes: minute);
  }
}

extension ExtDuration on Duration {
  TimeOfDay get asTime {
    // You may add seconds if needed
    return TimeOfDay(hour: inHours, minute: inMinutes % Duration.minutesPerHour);
  }
}