【问题标题】:flutter calendar carousel show events according to the month根据月份颤动日历轮播显示事件
【发布时间】:2021-04-01 05:12:29
【问题描述】:

我正在尝试使用颤振日历轮播构建日历应用程序。我需要做的是我想在用户滑动月份时显示分配给月份的事件。

checkCurrentMonth() {
    selectedMonth = DateTime.parse(_targetDateTime.toString()).month.toInt();
    selectedYear = DateTime.parse(_targetDateTime.toString()).year.toInt();

    _markedDateMap.events.forEach((key, value) {
      // print(_markedDateMap.events);

      print(DateTime.parse(key.toString()).month.toInt());
      if (selectedMonth == DateTime.parse(key.toString()).month.toInt() &&
          selectedYear == DateTime.parse(key.toString()).year.toInt()) {
        // print(_markedDateMap.events[key]);
        _selectedHolidays.add(_markedDateMap.events[key]);
      }
    });

    // for (var item in _selectedHolidays) {
    //   print("000000000000000 $item");
    //   gatheredEvents.add(GatherEvents.fromJson(item));
    // }
    print(_selectedHolidays[0].getTitle());
    print(_markedDateMap.events.length);
  }

我收到以下错误。

Class 'List<Event>' has no instance getter 'getTitle'.
Receiver: Instance(length:1) of '_GrowableList'
Tried calling: getTitle

这是我的 _markedDateMap

EventList<Event> _markedDateMap = new EventList<Event>(
    events: {
      new DateTime(2020, 12, 29): [
        new Event(
          date: new DateTime(2020, 12, 29),
          title: 'Poya Day',
          icon: _poyaeventIcon(DateTime(2020, 12, 29).day.toString()),
          dot: Container(
            margin: EdgeInsets.symmetric(horizontal: 1.0),
            color: Colors.red,
            height: 5.0,
            width: 5.0,
          ),
        ),
      ],
      new DateTime(2021, 01, 14): [
        new Event(
          date: new DateTime(2021, 01, 14),
          title: 'Tamil Thai Pongal Day',
          icon: _otheralleventIcon(DateTime(2021, 01, 14).day.toString()),
          dot: Container(
            margin: EdgeInsets.symmetric(horizontal: 1.0),
            color: Colors.red,
            height: 5.0,
            width: 5.0,
          ),
        ),
      ],
    },
  );

请帮帮我。

【问题讨论】:

  • 你的_markerdDateMap声明在哪里?
  • 嗨@dm_tr 我编辑了我的问题
  • 检查我的答案

标签: flutter calendar


【解决方案1】:

除了本机内置方法,您不能在List 上调用其他方法。您实际上是在Event 的列表中调用方法getTitle。如果要查看列表中所有事件的标题,则必须使用循环或获取特定索引。

for (var event in _selectedHolidays[0]) print(event.getTitle());

// or

print(_selectedHolidays[0].first.getTitle());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    相关资源
    最近更新 更多