mytooyo / board_datetime_picker

Picker to select date and time for Flutter. It is both a calendar and a picker, offering a variety of options as a package.
BSD 3-Clause "New" or "Revised" License
14 stars 12 forks source link

Add selection date for YESTERDAY #53

Closed lucasdidur closed 1 week ago

lucasdidur commented 3 weeks ago

By now, plugin only supports TODAY and TOMORROW, can you add YESTERDAY too? Or some way that can personalize?

mytooyo commented 3 weeks ago

@lucasdidur Currently, there is no personalized specification method available. Adding a “YESTERDAY” button is challenging as it may not be fully displayed depending on the screen size. Therefore, I will offer a feature that allows customization of the area where the “TODAY” and “TOMORROW” buttons are displayed.

lucasdidur commented 3 weeks ago

Maybe you could add an enum to specify whether you want to show YESTERDAY or TOMORROW. For example, I use data pick to record expenses, so YESTERDAY is more useful to me than TOMORROW, because if I forget to record it (common) it would be faster to select.

Another question would be whether I could show the drag handle with 3 (mini) or 7 positions (big)

mytooyo commented 3 weeks ago

@lucasdidur Added the ability to customize the action area. And expanded controller to allow date manipulation. If you want to use your own buttons, please add a controller as a parameter and call a method such as changeDateTime

final controller = BoardDateTimeController();

await showBoardDateTimePicker(
  context: context,
  ...
  controller: controller,
    onTopActionBuilder: (context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 16),
      child: Wrap(
        alignment: WrapAlignment.center,
        spacing: 8,
        children: [
          IconButton(
            onPressed: () {
              controller.changeDateTime(
                  date.value.add(const Duration(days: -1)));
            },
            icon: const Icon(Icons.arrow_back_rounded),
          ),
          IconButton(
            onPressed: () {
              controller.changeDateTime(DateTime.now());
            },
            icon: const Icon(Icons.stop_circle_rounded),
          ),
          IconButton(
            onPressed: () {
              controller.changeDateTime(
                  date.value.add(const Duration(days: 1)));
            },
            icon: const Icon(Icons.arrow_forward_rounded),
          ),
        ],
      ),
    );
  },
);

Yesterday button is specified by adding actionButtonTypes to BoardDateTimeOptions.

options: BoardDateTimeOptions(
  actionButtonTypes: [
    BoardDateButtonType.yesterday,
    BoardDateButtonType.today,
  ],
),

Another question would be whether I could show the drag handle with 3 (mini) or 7 positions (big)

The dragandle uses the showModalBottomSheet of the flutter standard, so it cannot be changed. However, since a headerWidget can be specified, it is possible to display handle with it.

headerWidget: Padding(
  padding: const EdgeInsets.only(top: 16),
  child: Wrap(
    spacing: 6,
    children: [
      for (var i = 0; i < 3; i++)
        Container(
          width: 6,
          height: 6,
          decoration: const BoxDecoration(
            shape: BoxShape.circle,
            color: Colors.grey,
          ),
        )
    ],
  ),
),