【发布时间】:2020-06-12 18:59:19
【问题描述】:
我是 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;
}
我的新小部件
Widget _buildEventsMarker2(DateTime date, List events, markerColors) {
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: markerColors,
),
width: 10.0,
height: 10.0,
);
}
【问题讨论】:
-
你好,有什么新鲜事吗?
-
你找到办法了吗?