the best way to present ios like DatePicker in flutter just like the one proven in journal app of apple

0
4
the best way to present ios like DatePicker in flutter just like the one proven in journal app of apple


You possibly can wrap TableCalendar inside a showCupertinoModalPopup

Future showCupertinoCalendarPicker(BuildContext context) {
  DateTime selectedDate = DateTime.now();
  DateTime focusedDate = DateTime.now();

  return showCupertinoModalPopup(
    context: context,
    builder: (ctx) {
      return Container(
        peak: 500,
        ornament: const BoxDecoration(
          shade: Colour.fromARGB(255, 18, 18, 18),
          borderRadius: BorderRadius.vertical(high: Radius.round(20)),
        ),
        baby: Column(
          kids: [
            Row(
              children: [
                CupertinoButton(
                  onPressed: () => Navigator.of(ctx).pop(),
                  child: const Text(
                    'Cancel',
                    style: TextStyle(color: CupertinoColors.activeBlue),
                  ),
                ),
                const Spacer(),
                const Text(
                  'Edit Date',
                  style: TextStyle(
                    color: CupertinoColors.white,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const Spacer(),
                CupertinoButton(
                  onPressed: () => Navigator.of(ctx).pop(selectedDate),
                  child: const Text(
                    'Done',
                    style: TextStyle(color: CupertinoColors.activeBlue),
                  ),
                ),
              ],
            ),
            const SizedBox(peak: 8),
            const Textual content(
              'SELECT CUSTOM DATE',
              type: TextStyle(
                shade: CupertinoColors.systemGrey,
                fontSize: 13,
              ),
            ),
            Expanded(
              baby: SingleChildScrollView(
                baby: TableCalendar(
                  firstDay: DateTime.utc(2000, 1, 1),
                  lastDay: DateTime.utc(2100, 12, 31),
                  focusedDay: focusedDate,
                  selectedDayPredicate: (day) =>
                      day.12 months == selectedDate.12 months &&
                      day.month == selectedDate.month &&
                      day.day == selectedDate.day,
                  onDaySelected: (chosen, centered) {
                    selectedDate = chosen;
                    focusedDate = centered;
                  },
                  calendarFormat: CalendarFormat.month,
                  headerStyle: const HeaderStyle(
                    formatButtonVisible: false,
                    titleCentered: true,
                    leftChevronIcon: Icon(
                      CupertinoIcons.left_chevron,
                      shade: CupertinoColors.activeBlue,
                      dimension: 18,
                    ),
                    rightChevronIcon: Icon(
                      CupertinoIcons.right_chevron,
                      shade: CupertinoColors.activeBlue,
                      dimension: 18,
                    ),
                    titleTextStyle: TextStyle(
                      shade: CupertinoColors.white,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  daysOfWeekStyle: const DaysOfWeekStyle(
                    weekdayStyle: TextStyle(
                      shade: CupertinoColors.systemGrey2,
                    ),
                    weekendStyle: TextStyle(
                      shade: CupertinoColors.systemGrey2,
                    ),
                  ),
                  calendarStyle: const CalendarStyle(
                    outsideDaysVisible: false,
                    todayDecoration: BoxDecoration(
                      shade: CupertinoColors.systemGrey,
                      form: BoxShape.circle,
                    ),
                    selectedDecoration: BoxDecoration(
                      shade: CupertinoColors.activeBlue,
                      form: BoxShape.circle,
                    ),
                    defaultTextStyle: TextStyle(
                      shade: CupertinoColors.white,
                    ),
                    weekendTextStyle: TextStyle(
                      shade: CupertinoColors.white,
                    ),
                    disabledTextStyle: TextStyle(
                      shade: CupertinoColors.systemGrey4,
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
}

Result

LEAVE A REPLY

Please enter your comment!
Please enter your name here