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