HomeiOS Developmentthe way to present ios like DatePicker in flutter just like the...

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


You’ll be able to 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(
          colour: Shade.fromARGB(255, 18, 18, 18),
          borderRadius: BorderRadius.vertical(prime: Radius.round(20)),
        ),
        baby: Column(
          youngsters: [
            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',
              model: TextStyle(
                colour: 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,
                      colour: CupertinoColors.activeBlue,
                      dimension: 18,
                    ),
                    rightChevronIcon: Icon(
                      CupertinoIcons.right_chevron,
                      colour: CupertinoColors.activeBlue,
                      dimension: 18,
                    ),
                    titleTextStyle: TextStyle(
                      colour: CupertinoColors.white,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  daysOfWeekStyle: const DaysOfWeekStyle(
                    weekdayStyle: TextStyle(
                      colour: CupertinoColors.systemGrey2,
                    ),
                    weekendStyle: TextStyle(
                      colour: CupertinoColors.systemGrey2,
                    ),
                  ),
                  calendarStyle: const CalendarStyle(
                    outsideDaysVisible: false,
                    todayDecoration: BoxDecoration(
                      colour: CupertinoColors.systemGrey,
                      form: BoxShape.circle,
                    ),
                    selectedDecoration: BoxDecoration(
                      colour: CupertinoColors.activeBlue,
                      form: BoxShape.circle,
                    ),
                    defaultTextStyle: TextStyle(
                      colour: CupertinoColors.white,
                    ),
                    weekendTextStyle: TextStyle(
                      colour: CupertinoColors.white,
                    ),
                    disabledTextStyle: TextStyle(
                      colour: CupertinoColors.systemGrey4,
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
}

Result

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments