我是 flutter 的新手,从table_calendar示例代码中学习,我正在尝试修改“Widget _buildTableCalendarWithBuilders”,以便它可以打印具有不同颜色的多个标记,有人可以告诉我正确的方法吗?
我需要的结果是当在字符串中找到“Apple”时,打印一个红点。当字符串中找到“Orange”时,打印一个黑点,如果两者都存在,则日期框应该有红点和黑点。
下面是我的代码
markersBuilder: (context, date, events, holidays) {
final children = <Widget>[];
String checkString = events.toString();
if (checkString.contains('Apple')) {
children.add(
Positioned(
right: 1,
bottom: 1,
child: _buildEventsMarker2(date, events, Colors.red),
),
);
}
if (checkString.contains('Orange')) {
children.add(
Positioned(
right: 1,
bottom: 1,
child: _buildEventsMarker2(date, events, Colors.black),
),
);
}
if (holidays.isNotEmpty) {
children.add(
Positioned(
right: -2,
top: -2,
child: _buildHolidaysMarker(),
),
);
}
return children;
}
Run Code Online (Sandbox Code Playgroud)
我的新小部件
Widget _buildEventsMarker2(DateTime date, List events, markerColors) {
return …Run Code Online (Sandbox Code Playgroud)