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