index.dart 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import 'package:farmer_client/models/addressController.dart';
  2. import 'package:farmer_client/widgets/layout/BasicPage.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:get/get.dart';
  7. import 'package:intl/intl.dart';
  8. class OrderConfirmation extends BasicPage {
  9. TextEditingController _unameController = TextEditingController();
  10. GlobalKey _formKey = GlobalKey<FormState>();
  11. final selectDate = Rx<DateTime>(DateTime.now()); //选择的时间
  12. final workingArea = Rxn(0);
  13. AddressController addressController = AddressController.t;
  14. @override
  15. Widget builder(BuildContext context) {
  16. naviTitle = '咨讯';
  17. return Container(
  18. height: 700.h,
  19. child: Form(
  20. key: _formKey, //设置globalKey,用于后面获取FormState
  21. autovalidateMode: AutovalidateMode.onUserInteraction,
  22. child: Column(
  23. children: <Widget>[
  24. Container(
  25. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  26. alignment: Alignment.topLeft,
  27. child: Text(
  28. '作业面积/公顷',
  29. style: TextStyle(
  30. color: Color(0xff222222),
  31. fontSize: 17.sp,
  32. fontWeight: FontWeight.bold),
  33. ),
  34. ),
  35. TextFormField(
  36. // autofocus: true,
  37. keyboardType: TextInputType.number,
  38. controller: _unameController,
  39. decoration: const InputDecoration(
  40. isCollapsed: true,
  41. contentPadding:
  42. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  43. counterText: '', //去掉计数
  44. /// UnderlineInputBorder 只有下边框 默认使用的就是下边框
  45. border: UnderlineInputBorder(
  46. borderRadius: BorderRadius.all(Radius.circular(10)),
  47. borderSide: BorderSide(
  48. color: Color(0x30000000),
  49. width: 2.0,
  50. ),
  51. ),
  52. floatingLabelBehavior: FloatingLabelBehavior.never,
  53. hintText: "请输入具体面积(公顷)",
  54. ),
  55. onChanged: (e) {
  56. workingArea.value = e as int?;
  57. },
  58. // 校验用户名
  59. validator: (v) {
  60. return v!.trim().isNotEmpty ? null : "作业面积/公顷不能为空";
  61. },
  62. ),
  63. Container(
  64. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  65. alignment: Alignment.topLeft,
  66. child: Text(
  67. '作业时间:',
  68. style: TextStyle(
  69. color: Color(0xff222222),
  70. fontSize: 17.sp,
  71. fontWeight: FontWeight.bold),
  72. ),
  73. ),
  74. Container(
  75. width: 345.w,
  76. padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
  77. decoration: const BoxDecoration(
  78. border: Border(
  79. bottom: BorderSide(width: 1, color: Color(0x20000000)
  80. // 0x17000000
  81. )),
  82. ),
  83. child: Row(
  84. children: [
  85. Image(
  86. image: AssetImage('images/icons/timeImage.png'),
  87. fit: BoxFit.cover,
  88. width: 18.w,
  89. height: 18.w,
  90. ),
  91. Padding(
  92. padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
  93. child: GestureDetector(
  94. onTap: () async {
  95. var handleChnage = await showDatePicker(
  96. context: context,
  97. helpText: '请选择作业开始时间',
  98. cancelText: '取消',
  99. confirmText: '确定',
  100. initialDate: selectDate.value == null
  101. ? DateTime.now()
  102. : selectDate.value,
  103. firstDate: DateTime.now(),
  104. lastDate: DateTime(2030),
  105. );
  106. selectDate.value = handleChnage!;
  107. print('${selectDate}+');
  108. },
  109. child: Text(selectDate == null
  110. ? '请选择日期'
  111. : '${DateFormat("yyyy-MM-dd").format(selectDate.value)}'),
  112. ),
  113. )
  114. ],
  115. )),
  116. Container(
  117. margin: EdgeInsets.fromLTRB(15, 20, 0, 0),
  118. alignment: Alignment.topLeft,
  119. child: Text(
  120. '作业位置:',
  121. style: TextStyle(
  122. color: Color(0xff222222),
  123. fontSize: 17.sp,
  124. fontWeight: FontWeight.bold),
  125. ),
  126. ),
  127. Container(
  128. width: 345.w,
  129. padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
  130. decoration: BoxDecoration(
  131. border: Border(
  132. bottom: BorderSide(width: 1, color: Color(0x20000000)
  133. // 0x17000000
  134. )),
  135. ),
  136. child: Row(
  137. mainAxisAlignment: MainAxisAlignment.start,
  138. children: [
  139. Image(
  140. image: AssetImage('images/gpsImgae.png'),
  141. fit: BoxFit.cover,
  142. width: 14.w,
  143. height: 17.h,
  144. ),
  145. Padding(
  146. padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
  147. child: GestureDetector(
  148. onTap: () {
  149. Get.toNamed('/addressList',
  150. arguments: {'isBack': true});
  151. },
  152. child: Container(
  153. width: 290.w,
  154. child: Obx(() => Text(
  155. addressController.address.value.address
  156. .toString(),
  157. softWrap: true,
  158. maxLines: 1,
  159. textAlign: TextAlign.left,
  160. overflow: TextOverflow.ellipsis,
  161. )),
  162. ),
  163. ))
  164. ],
  165. ),
  166. ),
  167. Spacer(),
  168. Container(
  169. alignment: Alignment.bottomCenter,
  170. child: SizedBox(
  171. width: 315.w,
  172. height: 49.h,
  173. child: ElevatedButton(
  174. onPressed: () {
  175. if ((_formKey.currentState as FormState).validate()) {
  176. var a = {selectDate, workingArea};
  177. print('我确定了$a');
  178. //验证通过提交数据
  179. Get.toNamed('/orderPageInfo');
  180. }
  181. },
  182. child: const Text(
  183. "确定",
  184. style: TextStyle(
  185. fontSize: 18,
  186. color: Colors.white,
  187. fontWeight: FontWeight.bold),
  188. ),
  189. style: ButtonStyle(
  190. elevation: MaterialStateProperty.all(0),
  191. backgroundColor:
  192. MaterialStateProperty.all(const Color(0xFFFF703B)),
  193. shape: MaterialStateProperty.all(
  194. const RoundedRectangleBorder(
  195. borderRadius:
  196. BorderRadius.all(Radius.circular(24.4)))),
  197. ),
  198. ),
  199. ),
  200. ),
  201. Container(
  202. margin: EdgeInsets.fromLTRB(0, 30.w, 0, 30.w),
  203. alignment: Alignment.bottomCenter,
  204. child: SizedBox(
  205. width: 315.w,
  206. height: 49.h,
  207. child: ElevatedButton(
  208. onPressed: () {
  209. Get.back();
  210. },
  211. child: const Text(
  212. "取消",
  213. style: TextStyle(
  214. fontSize: 18,
  215. color: Color(0xFFFF703B),
  216. fontWeight: FontWeight.bold),
  217. ),
  218. style: ButtonStyle(
  219. side: MaterialStateProperty.all(
  220. BorderSide(width: 1, color: Color(0xFFFF703B))), //边框
  221. elevation: MaterialStateProperty.all(0),
  222. backgroundColor: MaterialStateProperty.all(Colors.white),
  223. shape: MaterialStateProperty.all(
  224. RoundedRectangleBorder(
  225. borderRadius:
  226. BorderRadius.all(Radius.circular(24.4))),
  227. ),
  228. ),
  229. ),
  230. ),
  231. ),
  232. ],
  233. ),
  234. ),
  235. );
  236. }
  237. }