Browse Source

优化日程组件

gavin.chen 2 years ago
parent
commit
f5962036dd
1 changed files with 29 additions and 6 deletions
  1. 29 6
      lib/calendar_page/month_calendar/schedule_item.dart

+ 29 - 6
lib/calendar_page/month_calendar/schedule_item.dart

@@ -12,8 +12,10 @@ class SchedualItem extends StatefulWidget {
 }
 
 class _SchedualItemState extends State<SchedualItem> {
-  get scheduleType => widget.scheduleData.type;
-  get schedule => widget.scheduleData;
+  ScheduleType get scheduleType => widget.scheduleData.type;
+  Schedule get schedule => widget.scheduleData;
+  bool _isSelected = false; // 是否选中状态
+  ////TODO:[Gavin] 监听一个popupController的关闭事件,关闭时将选中状态置为false
   @override
   Widget build(BuildContext context) {
     return Material(
@@ -23,6 +25,9 @@ class _SchedualItemState extends State<SchedualItem> {
           borderRadius: BorderRadius.circular(5),
         ),
         onTap: () {
+          setState(() {
+            _isSelected = !_isSelected;
+          });
           ScaffoldMessenger.of(context).showSnackBar(
             SnackBar(
               backgroundColor: scheduleType.color,
@@ -36,9 +41,7 @@ class _SchedualItemState extends State<SchedualItem> {
           height: widget.itemHeight,
           padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 0),
           decoration: BoxDecoration(
-            // color: scheduleType.isSelected
-            //     ? scheduleType.color.withOpacity(0.2)
-            //     : Colors.transparent,
+            color: _isSelected ? scheduleType.color : Colors.transparent,
             borderRadius: BorderRadius.circular(5),
           ),
           child: Row(
@@ -52,10 +55,22 @@ class _SchedualItemState extends State<SchedualItem> {
                 ),
               ),
               const SizedBox(width: 5),
+              Text(
+                _getStartTime(schedule.startTime),
+                style: TextStyle(
+                  fontSize: 12,
+                  color: _isSelected
+                      ? Colors.white
+                      : const Color.fromARGB(167, 0, 0, 0),
+                ),
+                overflow: TextOverflow.ellipsis,
+              ),
               Expanded(
                 child: Text(
                   breakWord(schedule.title),
-                  style: const TextStyle(fontSize: 12),
+                  style: TextStyle(
+                      fontSize: 12,
+                      color: _isSelected ? Colors.white : Colors.black),
                   overflow: TextOverflow.ellipsis,
                 ),
               ),
@@ -77,4 +92,12 @@ class _SchedualItemState extends State<SchedualItem> {
     }
     return breakWord;
   }
+
+  static String _getStartTime(DateTime? startTime) {
+    if (startTime == null) {
+      // TODO: i18n
+      return '全天';
+    }
+    return '${startTime.hour}:${startTime.minute}';
+  }
 }