English 中文(简体)
包装表——食面液碎
原标题:set background color for day in package table_calendar flutter

I m currently using table_calendar, I create a list to store my event then use event loader to show that. But I want, if that day has event it will have a random background color for that cell of day, or maybe can be selectted like this image not like the demo one with black dot ? How can I do that enter image description here

问题回答

您可以按每个单元进行定制。

例如:

 Widget _buildCellDate(DateTime day, {DateTime? focusedDay}) {
    return Container(
      margin: const EdgeInsets.all(5),
      alignment: Alignment.center,
      decoration: BoxDecoration(
        shape: (day == focusedDay) ? BoxShape.circle : BoxShape.rectangle,
        color: bgclr, // you custom color here
        borderRadius: (day == focusedDay) ? null : BorderRadius.circular(4),
      ),
      child: Text(
        day.day.toString(),
        style: TextStyle(color: _getTxtColor(bgclr)),
      ),
    );
  }

我现在请您使用<代码>_buildCellDate。 表 日历:

TableCalendar<MyModel>(
  // another setup here
  startingDayOfWeek: StartingDayOfWeek.monday,
  calendarBuilders: CalendarBuilders(
    selectedBuilder: (context, day, focusedDay) =>
        _buildCellDate(day, focusedDay: focusedDay),
    defaultBuilder: (context, day, focusedDay) => _buildCellDate(day),
    todayBuilder: (context, day, focusedDay) => _buildCellDate(day),
  ),
}

定制以下网站:calendarBuilders。 您可定制<条码>选择、<条码>至日<>和<条码>。

这里的例子有: 我制作了一个日历,“HeatMap”植被。

“在此处的影像描述”/</a





相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...

热门标签