field_control.dart 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import 'package:track_common/service/map_watch.dart';
  2. import 'package:track_common/view/home/field_control/field_control.dart';
  3. import 'package:track_common/view/home/field_control/field_control_controller.dart';
  4. import 'package:track_common/widget/prelude.dart';
  5. class FieldControlPageImpl extends FieldControlPage {
  6. const FieldControlPageImpl({super.key});
  7. @override
  8. Widget get rightColumn {
  9. return Obx(() => Container(
  10. width: 263,
  11. padding: const EdgeInsets.all(6.4),
  12. height: double.infinity,
  13. color: Colors.white,
  14. child: Column(
  15. children: [
  16. SizedBox(
  17. width: double.infinity,
  18. child: DarkButton(
  19. child: const Text('注册比赛'),
  20. onPressed: () {
  21. Get.dialog(const RegisterDialog());
  22. })),
  23. Expanded(
  24. child: ListView(
  25. children: controller.eventList
  26. .map((element) => eventView(element))
  27. .toList(),
  28. ),
  29. )
  30. ],
  31. )));
  32. }
  33. Widget eventView(EventOnMap event) {
  34. return Card(
  35. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(3.56)),
  36. child: Row(
  37. children: [
  38. Text(event.name),
  39. Text('(${event.userList.length} 人)'),
  40. const Spacer(),
  41. IconButton(
  42. onPressed: () {},
  43. icon: const Icon(Icons.arrow_drop_down_outlined))
  44. ],
  45. ),
  46. );
  47. }
  48. }
  49. class FieldControlControllerImpl extends FieldControlController {
  50. var registerName = '';
  51. final registerStartAt = Rx<TimeOfDay?>(null);
  52. final registerStopAt = Rx<TimeOfDay?>(null);
  53. }
  54. class RegisterDialog extends GetView<FieldControlController> {
  55. const RegisterDialog({super.key});
  56. FieldControlControllerImpl get c => controller as FieldControlControllerImpl;
  57. @override
  58. Widget build(BuildContext context) {
  59. return AlertDialog(
  60. title: const Center(
  61. child: Text(
  62. '注册比赛',
  63. style: TextStyle(fontSize: 17),
  64. )),
  65. backgroundColor: Colors.white,
  66. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(17.78)),
  67. content: SizedBox(
  68. width: 75.38,
  69. child: ListView(
  70. shrinkWrap: true,
  71. children: [
  72. const _TextField(hint: '请选择活动'),
  73. const SizedBox(height: 21.34),
  74. _TextField(
  75. hint: '请输入名称',
  76. onChanged: (v) {
  77. c.registerName = v;
  78. }),
  79. const SizedBox(height: 21.34),
  80. Row(children: [
  81. Expanded(
  82. child: Obx(() => _TextField(
  83. hint: '开始时间',
  84. readOnly: true,
  85. initText: c.registerStartAt.value?.format(context),
  86. onTap: () async {
  87. c.registerStartAt.value = await _showTimePicker(
  88. context, c.registerStartAt.value);
  89. }))),
  90. const SizedBox(width: 15.64),
  91. Expanded(
  92. child: _TextField(
  93. hint: '结束时间',
  94. readOnly: true,
  95. initText: c.registerStopAt.value?.format(context),
  96. onTap: () async {
  97. c.registerStopAt.value = await _showTimePicker(
  98. context, c.registerStopAt.value);
  99. })),
  100. ]),
  101. Row(
  102. mainAxisSize: MainAxisSize.min,
  103. children: [
  104. Switch(value: true, onChanged: (v) {}),
  105. const Text('查询密码')
  106. ],
  107. ),
  108. SizedBox(
  109. width: double.infinity,
  110. child: DarkButton(child: const Text('注 册'), onPressed: () {}))
  111. ],
  112. )),
  113. );
  114. }
  115. Future<TimeOfDay?> _showTimePicker(
  116. BuildContext context, TimeOfDay? init) async {
  117. final TimeOfDay? time = await showTimePicker(
  118. context: context,
  119. initialTime: init ?? TimeOfDay.now(),
  120. );
  121. return time;
  122. }
  123. }
  124. class _TextField extends StatelessWidget {
  125. const _TextField(
  126. {required this.hint,
  127. this.onChanged,
  128. this.readOnly = false,
  129. this.onTap,
  130. this.initText});
  131. final String hint;
  132. final void Function(String)? onChanged;
  133. final bool readOnly;
  134. final void Function()? onTap;
  135. final String? initText;
  136. @override
  137. Widget build(BuildContext context) {
  138. return SizedBox(
  139. height: 34.13,
  140. child: TextFormField(
  141. key: GlobalKey(),
  142. initialValue: initText,
  143. maxLines: 1,
  144. style: const TextStyle(fontSize: 11.38),
  145. onChanged: onChanged,
  146. onTap: onTap,
  147. readOnly: readOnly,
  148. decoration: InputDecoration(
  149. hintText: hint,
  150. border: OutlineInputBorder(
  151. borderSide:
  152. const BorderSide(width: 0.71, color: Color(0xff818181)),
  153. borderRadius: BorderRadius.circular(2.13),
  154. ),
  155. isDense: true,
  156. contentPadding: const EdgeInsets.all(8.53)),
  157. ),
  158. );
  159. }
  160. }