【问题标题】:Showing Event from API to Flutter Carousel Calender将事件从 API 显示到 Flutter 轮播日历
【发布时间】:2021-02-14 05:33:19
【问题描述】:

我想使用 Rest Api 显示轮播日历并标记学生的出席、缺席和离开。我需要用不同的颜色显示这些事件。 API 中已存在该事件。

【问题讨论】:

  • 请更具体。您需要添加一些代码来描述您到目前为止所做的事情以及您遇到的问题?您是否坚持创建轮播日历或在日历中显示事件或两者兼而有之?您是否尝试过使用可用的日历包?我知道有一些可以轻松帮助您构建相同的东西。
  • @RaviSinghLodhi 我已经完成了轮播日历。然后现在我需要通过其余 api 的特定响应在日历中显示缺席、在场和离开日期。我只想显示特定日期这些事件到日历上。就是这样
  • 日历轮播你用的是哪个库?
  • @RaviSinghLodhi flutter_calendar_carousel: ^1.4.12
  • 您可以使用customDayBuilder 属性。您从 API 中获得了哪些类型的数据?

标签: api flutter dart calendar carousel


【解决方案1】:

您必须将 API 中的时间戳数据转换为 DateTime 对象。

DateTime dateTime = DateTime.parse(timestamp);

然后使用customDayBuilder 属性来定义具有您想要的颜色的适当小部件。

customDayBuilder: (   /// you can provide your own build function to make custom day containers
        bool isSelectable,
        int index,
        bool isSelectedDay,
        bool isToday,
        bool isPrevMonthDay,
        TextStyle textStyle,
        bool isNextMonthDay,
        bool isThisMonthDay,
        DateTime day,
      ) {
          /// If you return null, [CalendarCarousel] will build container for current [day] with default function.
          /// This way you can build custom containers for specific days only, leaving rest as default.


          if (day.difference(dateTime).inDays == 0) {
            // Do additional checks for status, remarks or for checking
            // whether the day should be marked as absent, present or something else
            return Container(
              decoration: BoxDecoration(
                color: Colors.red // Change this color according to your case.
                shape: BoxShape.circle,
            );
          } else {
            return null; // returning null will build container for current [day] with default function.
          }
      },

【讨论】:

    猜你喜欢
    • 2020-06-02
    • 2021-04-01
    • 2021-02-28
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 2020-06-02
    相关资源
    最近更新 更多