view.dart 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../../../../common/models/index.dart';
  4. import '../../../../common/routers/index.dart';
  5. import '../../../../common/style/index.dart';
  6. import '../../../../common/utils/index.dart';
  7. import '../../../../common/widgets/index.dart';
  8. import '../calendar_const.dart';
  9. import '../widgets/widgets.dart';
  10. import 'index.dart';
  11. class CreateCalendarEventPage extends GetView<CreateCalendarEventController> {
  12. const CreateCalendarEventPage({Key? key}) : super(key: key);
  13. static Future<dynamic> openUpdate(EventInfo info) async {
  14. await Get.toNamed(O2OARoutes.appCalendarEventCreate,
  15. arguments: {"eventInfo": info});
  16. }
  17. @override
  18. Widget build(BuildContext context) {
  19. return GetBuilder<CreateCalendarEventController>(
  20. builder: (_) {
  21. return Scaffold(
  22. appBar: AppBar(
  23. title: Obx(() => Text(controller.state.isUpdate
  24. ? 'calendar_action_update_event'.tr
  25. : 'calendar_action_create_event'.tr)),
  26. actions: [
  27. Obx(() => controller.state.isUpdate
  28. ? TextButton(
  29. onPressed: () => controller.updateEvent(),
  30. child: Text('save'.tr,
  31. style: AppTheme.whitePrimaryTextStyle))
  32. : TextButton(
  33. onPressed: () => controller.saveEvent(),
  34. child: Text('save'.tr,
  35. style: AppTheme.whitePrimaryTextStyle))),
  36. ]),
  37. body: SafeArea(
  38. child: ListView(
  39. children: [const SizedBox(height: 8), formView(context)]),
  40. ),
  41. );
  42. },
  43. );
  44. }
  45. Widget formView(BuildContext context) {
  46. return O2UI.sectionOutBox( Column(children: [
  47. // 日程标题
  48. TextField(
  49. controller: controller.titleController,
  50. decoration: InputDecoration(
  51. hintText: "calendar_event_form_title_hint".tr,
  52. label: Text('calendar_event_form_title'.tr)),
  53. ),
  54. // 日历选择
  55. Obx(()=>O2UI.lineWidget(
  56. 'calendar_event_form_calendar'.tr,
  57. Text(controller.state.calendar.value == null
  58. ? ''
  59. : (controller.state.calendar.value?.name ?? '')),
  60. ontap: () => controller.pickCalendar())),
  61. const Divider(height: 1),
  62. // 全天
  63. Obx(()=>Padding(
  64. padding: const EdgeInsets.only(top: 10, bottom: 10),
  65. child: Row(
  66. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  67. mainAxisSize: MainAxisSize.max,
  68. children: [
  69. Text(
  70. 'calendar_event_all_day'.tr,
  71. style: Theme.of(context).textTheme.bodyLarge,
  72. ),
  73. const SizedBox(width: 10),
  74. Switch(
  75. value: controller.state.allDay,
  76. onChanged: (bool value) {
  77. controller.changeAllDay(value);
  78. },
  79. )
  80. ],
  81. ))),
  82. const Divider(height: 1),
  83. // 开始日期
  84. Obx(()=>O2UI.lineWidget('calendar_event_form_start_date'.tr,
  85. Text(controller.state.startDate),
  86. ontap: () => controller.selectStartDate())),
  87. const Divider(height: 1),
  88. Obx(()=>Visibility(
  89. visible: !controller.state.allDay,
  90. child: O2UI.lineWidget('calendar_event_form_start_time'.tr,
  91. Text(controller.state.startTime),
  92. ontap: () => controller.selectStartTime()))),
  93. Obx(()=>Visibility(
  94. visible: !controller.state.allDay, child: const Divider(height: 1))),
  95. // 结束日期
  96. Obx(()=>O2UI.lineWidget(
  97. 'calendar_event_form_end_date'.tr, Text(controller.state.endDate),
  98. ontap: () => controller.selectEndDate())),
  99. const Divider(height: 1),
  100. Obx(()=>Visibility(
  101. visible: !controller.state.allDay,
  102. child: O2UI.lineWidget('calendar_event_form_end_time'.tr,
  103. Text(controller.state.endTime),
  104. ontap: () => controller.selectEndTime()))),
  105. Obx(()=>Visibility(
  106. visible: !controller.state.allDay, child: const Divider(height: 1))),
  107. // 颜色
  108. Obx(() {
  109. final eventColor = controller.state.eventColor;
  110. OLogger.d('obx 颜色 $eventColor');
  111. return ColorChooseView(
  112. color: eventColor,
  113. onChange: ((color) => controller.chooseEventColor(color)));
  114. }),
  115. const Divider(height: 1),
  116. // 提醒
  117. Obx(()=>O2UI.lineWidget('calendar_event_form_alert'.tr,
  118. Text(O2Calendar.remindOptions[controller.state.remind] ?? ''),
  119. ontap: () => controller.selectRemind())),
  120. const Divider(height: 1),
  121. // 重复
  122. Obx(()=>O2UI.lineWidget('calendar_event_form_repeat'.tr,
  123. Text(O2Calendar.repeatOptions[controller.state.repeat] ?? ''),
  124. ontap: () => controller.selectRepeat())),
  125. const Divider(height: 1),
  126. Obx(()=>Visibility(
  127. visible: controller.state.repeat != 'NONE' &&
  128. controller.state.repeat != 'WEEKLY',
  129. child: O2UI.lineWidget('calendar_event_form_repeat_end'.tr,
  130. Text(controller.state.repeatEndDate),
  131. ontap: () => controller.selectRepeatEndDate()))),
  132. Obx(()=>Visibility(
  133. visible: controller.state.repeat != 'NONE' &&
  134. controller.state.repeat != 'WEEKLY',
  135. child: const Divider(height: 1))),
  136. Obx(()=>Visibility(
  137. visible: controller.state.repeat == 'WEEKLY',
  138. child: weekDayChooseView(context))),
  139. const Divider(height: 1),
  140. //
  141. TextField(
  142. controller: controller.commentController,
  143. maxLines: 3,
  144. decoration: InputDecoration(
  145. hintText: "calendar_event_form_content_hint".tr,
  146. label: Text('calendar_event_form_content'.tr)),
  147. ),
  148. const SizedBox(height: 5),
  149. Obx(()=>Visibility(
  150. visible: controller.state.isUpdate,
  151. child:Padding(
  152. padding: const EdgeInsets.only(
  153. top: 40, bottom: 10, left: 15, right: 15),
  154. child: SizedBox(
  155. width: double.infinity,
  156. height: 44,
  157. child: O2ElevatedButton(() => controller.deleteEvent(),
  158. Text(
  159. 'calendar_action_delete_event'.tr,
  160. style: const TextStyle(fontSize: 18),
  161. ))),
  162. )))
  163. ]), context);
  164. }
  165. ///
  166. Widget weekDayChooseView(BuildContext context) {
  167. return Obx(() {
  168. final weekdays = controller.state.weekDayKeys.toList();
  169. return Padding(
  170. padding: const EdgeInsets.all(10),
  171. child: Wrap(
  172. spacing: 8.0, // 水平间距
  173. runSpacing: 4.0, // 垂直间距
  174. children: O2Calendar.weekDays.entries
  175. .map((entry) => InkWell(
  176. onTap: () => controller.chooseWeekDay(entry.key),
  177. child: EllipticalText(entry.value,
  178. backgroundColor: weekdays.contains(entry.key)
  179. ? Theme.of(context).primaryColor
  180. : Theme.of(context).highlightColor)))
  181. .toList(),
  182. ));
  183. });
  184. }
  185. }