flutter table_calendar формат дней недели

Рейтинг: 0Ответов: 1Опубликовано: 19.06.2023

Не могу понять как сделать другой формат вывода дней недели: Сейчас у меня формат вывода такой: "вс, пн, вт, ср, чт,пт, сб". Но я хочу сделать его другим: "пн, вт, ср, чт,пт, сб, вс".

                child: Container(
                  width: double.infinity,
                  decoration: const BoxDecoration(
                      borderRadius: BorderRadius.only(
                          topRight: Radius.circular(50),
                          topLeft: Radius.circular(50)),
                      color: Colors.white),
                  child: Column(
                    children: [
                      Visibility(
                        visible: isSelected[0],
                        child: Column(
                          children: [
                            TableCalendar(
                              locale: 'ru_RU',
                              headerStyle: const HeaderStyle(
                                  formatButtonVisible: false,
                                  titleCentered: true,
                                  
                              ),
                              firstDay: DateTime.utc(2010, 10, 16),
                              lastDay: DateTime.utc(2030, 3, 14),
                              focusedDay: DateTime.now(),
                              calendarBuilders: CalendarBuilders(
                                defaultBuilder: (context, date, _) {
                                  if (date.weekday == 7) {
                                    return Container(
                                      margin: EdgeInsets.all(5),
                                      decoration: BoxDecoration(
                                        shape: BoxShape.circle,
                                        color: Colors.black,
                                      ),
                                      alignment: Alignment.center,
                                      child: Text(
                                        date.day.toString(),
                                        style: TextStyle(
                                          color: Colors.white,
                                        ),
                                      ),
                                    );
                                  } else {
                                    // Use the default builder for other days
                                    return null;
                                  }
                                },
                                outsideBuilder: (context, date, _) {
                                  if (date.weekday == DateTime.sunday) {
                                    return Container(
                                      margin: EdgeInsets.all(5),
                                      decoration: BoxDecoration(
                                        shape: BoxShape.circle,
                                        color: Colors.black,
                                      ),
                                      alignment: Alignment.center,
                                      child: Text(
                                        date.day.toString(),
                                        style: TextStyle(
                                          color: Colors.white,
                                        ),
                                      ),
                                    );
                                  }
                                },
                              ),
                            ),
                          ],
                        ),
                      ),
                      Visibility(
                          visible: isSelected[1],
                          child: Column(
                            children: [],
                          )),
                    ],
                  ),
                ),
              )```

Ответы

▲ 1

Тебе надо добавить:

startingDayOfWeek: StartingDayOfWeek.monday

Вот весь пример:

TableCalendar<Event>(
        firstDay: kFirstDay,
        lastDay: kLastDay,
        focusedDay: _focusedDay,
        selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
        rangeStartDay: _rangeStart,
        rangeEndDay: _rangeEnd,
        calendarFormat: _calendarFormat,
        rangeSelectionMode: _rangeSelectionMode,
        eventLoader: _getEventsForDay,
        // Сюда
        startingDayOfWeek: StartingDayOfWeek.monday,
        calendarStyle: CalendarStyle(
          // Use `CalendarStyle` to customize the UI
          outsideDaysVisible: false,
        ),
        onDaySelected: _onDaySelected,
        onRangeSelected: _onRangeSelected,
        onFormatChanged: (format) {
          if (_calendarFormat != format) {
            setState(() {
              _calendarFormat = format;
            });
          }
        },
        onPageChanged: (focusedDay) {
          _focusedDay = focusedDay;
        },
      ),