send_express_page.dart 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:city_pickers/city_pickers.dart';
  4. class SendExpressPage extends StatefulWidget {
  5. final Widget child;
  6. SendExpressPage({
  7. Key key,
  8. this.child
  9. }): super(key: key);
  10. _SendExpressPageState createState() => _SendExpressPageState();
  11. }
  12. class _SendExpressPageState extends State < SendExpressPage > with AutomaticKeepAliveClientMixin {
  13. ScrollController _scrollController = ScrollController();
  14. GlobalKey _sendPhoneKey = GlobalKey();
  15. GlobalKey _getPhoneKey = GlobalKey();
  16. String _sendPhoneStr = '';
  17. String _getPhoneStr = '';
  18. double tipWidth = 0;
  19. double tipHeight = 0;
  20. double tipPosX = 0;
  21. double tipPosY = 0;
  22. bool tipStatus = true;
  23. @override
  24. void initState() {
  25. super.initState();
  26. _scrollController.addListener(() {
  27. if (!tipStatus) {
  28. setState(() {
  29. tipStatus = true;
  30. });
  31. }
  32. print('滚动了');
  33. if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {}
  34. });
  35. }
  36. @override
  37. bool get wantKeepAlive => true;
  38. final Map < Object,
  39. String > sendInfo = {
  40. "icon": 'lib/images/icon_send.png',
  41. "title": "发件信息",
  42. "phone": "010-8788 6890",
  43. "code": "345678",
  44. "name": "朝阳门大阳汽贸",
  45. "address": "",
  46. "addressDetail": "朝阳门外大街28号"
  47. };
  48. final Map < Object,
  49. String > getInfo = {
  50. "icon": 'lib/images/icon_shoujian.png',
  51. "title": "收件信息",
  52. "name": "香河汽修厂",
  53. "phone": "010-6734 3426",
  54. "address": "",
  55. "addressDetail": "香河县东大街29号院18栋3单元206"
  56. };
  57. Map < String,
  58. String > _itemInfo = {
  59. "icon": "lib/images/icon_huowu.png",
  60. "title": "货物信息",
  61. "itemName": "汽车轮胎",
  62. "itemNo": "4",
  63. "expressPrice": "15",
  64. "collectionPrice": "15800",
  65. "supportPrice": "5000",
  66. "weight": "600",
  67. "itemDesc": "轮胎请核对数量轮胎请"
  68. };
  69. @override
  70. Widget build(BuildContext context) {
  71. return Container(
  72. child: Scaffold(
  73. appBar: AppBar(
  74. title: Text('发件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
  75. centerTitle: true,
  76. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  77. // leading: GestureDetector(
  78. // child: Icon(Icons.arrow_back),
  79. // onTap: (){
  80. // Navigator.pushReplacement(context, MaterialPageRoute(builder: (context){
  81. // return HomePage();
  82. // }));
  83. // },
  84. // ),
  85. ),
  86. body:
  87. Stack(
  88. children: < Widget > [
  89. Container(
  90. color: Color.fromRGBO(246, 246, 254, 1),
  91. padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(20), 0, ScreenUtil.getInstance().setHeight(20)),
  92. child: ListView(
  93. controller: _scrollController,
  94. children: < Widget > [
  95. _sendInfo(sendInfo, context),
  96. _getInfo(getInfo),
  97. _itemInfoWidget(_itemInfo),
  98. _submitBtn()
  99. ],
  100. ),
  101. ),
  102. Positioned(
  103. top: tipPosY,
  104. left: tipPosX,
  105. child: Offstage(
  106. offstage: tipStatus,
  107. child: Container(
  108. width: tipWidth,
  109. height: ScreenUtil.getInstance().setHeight(450),
  110. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  111. decoration: BoxDecoration(
  112. color: Color.fromRGBO(244, 248, 251, 1),
  113. ),
  114. child: ListView(
  115. children: < Widget > [
  116. _tipItem(),
  117. _tipItem(),
  118. ],
  119. ),
  120. ),
  121. )
  122. )
  123. ],
  124. ),
  125. resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误
  126. ),
  127. );
  128. }
  129. Widget _sendInfo(Map str, BuildContext context) {
  130. return Container(
  131. color: Colors.white,
  132. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  133. child: Column(
  134. children: < Widget > [
  135. _titleWidget(str['icon'], str['title']),
  136. _underLine(),
  137. _inputWiget('电话', 'sendPhone'),
  138. _contentWiget('企业编码', str['code'],true),
  139. _contentWiget('企业名称', str['name'],true),
  140. _cityWiget('城市/区域', str['address'], context),
  141. _lastContentWiget('详细地址', str['addressDetail'])
  142. ],
  143. )
  144. );
  145. }
  146. Widget _getInfo(Map str) {
  147. return Container(
  148. color: Colors.white,
  149. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  150. child: Column(
  151. children: < Widget > [
  152. _titleWidget(str['icon'], str['title']),
  153. _underLine(),
  154. _contentWiget('企业名称', str['name'],true),
  155. _inputWiget('电话', 'getPhone'),
  156. _cityWiget('城市/区域', str['address'], context),
  157. _lastContentWiget('详细地址', str['addressDetail'])
  158. ],
  159. )
  160. );
  161. }
  162. Widget _itemInfoWidget(Map _itemInfo) {
  163. return Container(
  164. child: Container(
  165. color: Colors.white,
  166. child: Column(
  167. crossAxisAlignment: CrossAxisAlignment.start,
  168. children: < Widget > [
  169. _titleWidget(_itemInfo['icon'], "货物信息"),
  170. _underLine(),
  171. _contentWiget("货物名称", _itemInfo["itemName"],true),
  172. _contentWiget("数量", _itemInfo["itemNo"]),
  173. _contentWiget("运费", _itemInfo["expressPrice"]),
  174. _contentWiget("代收", _itemInfo["collectionPrice"]),
  175. _contentWiget("保价", _itemInfo["supportPrice"]),
  176. _contentWiget("重量", _itemInfo["weight"]),
  177. _descWidget(_itemInfo['itemDesc'])
  178. ],
  179. ),
  180. )
  181. );
  182. }
  183. Widget _titleWidget(String iconUrl, String str) {
  184. return Container(
  185. height: ScreenUtil.getInstance().setHeight(90),
  186. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  187. child: Center(
  188. child: Row(
  189. mainAxisAlignment: MainAxisAlignment.start,
  190. children: < Widget > [
  191. Padding(
  192. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
  193. child: Image.asset(
  194. iconUrl,
  195. width: ScreenUtil.getInstance().setWidth(40),
  196. height: ScreenUtil.getInstance().setHeight(40),
  197. )
  198. ),
  199. Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
  200. ],
  201. ),
  202. ),
  203. );
  204. }
  205. Widget _underLine() {
  206. return Container(
  207. color: Color.fromRGBO(223, 223, 223, 1),
  208. height: ScreenUtil.getInstance().setHeight(1),
  209. );
  210. }
  211. Widget _inputWiget(String key, String tab) {
  212. return Padding(
  213. key: tab == 'sendPhone' ? _sendPhoneKey : _getPhoneKey,
  214. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  215. child: Column(
  216. children: < Widget > [
  217. SizedBox(
  218. height: ScreenUtil.getInstance().setHeight(89),
  219. child: Center(
  220. child: Row(
  221. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  222. children: < Widget > [
  223. Expanded(
  224. flex: 0,
  225. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  226. ),
  227. Expanded(
  228. child: Row(
  229. mainAxisAlignment: MainAxisAlignment.end,
  230. children: < Widget > [
  231. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  232. SizedBox(
  233. width: ScreenUtil.getInstance().setWidth(500),
  234. child: TextField(
  235. keyboardType: TextInputType.number,
  236. textAlign: TextAlign.end,
  237. decoration: InputDecoration(
  238. border: InputBorder.none
  239. ),
  240. onChanged: ((value) {
  241. if (tab == 'sendPhone') {
  242. if(value.length>=4){
  243. RenderObject sendPhoneObj = _sendPhoneKey.currentContext.findRenderObject();
  244. setState(() {
  245. tipWidth = sendPhoneObj.paintBounds.size.width;
  246. tipHeight = sendPhoneObj.paintBounds.size.height;
  247. tipPosX = sendPhoneObj.getTransformTo(null).getTranslation().x;
  248. tipPosY = sendPhoneObj.getTransformTo(null).getTranslation().y - ScreenUtil.getInstance().setHeight(90);
  249. tipStatus = false;
  250. });
  251. }else{
  252. setState(() {
  253. tipStatus = true;
  254. });
  255. }
  256. // print(tipWidth);
  257. // print(tipHeight);
  258. // print(tipPosX);
  259. // print(tipPosY);
  260. } else if (tab == 'getPhone') {
  261. if(value.length>=4){
  262. RenderObject sendPhoneObj = _getPhoneKey.currentContext.findRenderObject();
  263. setState(() {
  264. tipWidth = sendPhoneObj.paintBounds.size.width;
  265. tipHeight = sendPhoneObj.paintBounds.size.height;
  266. tipPosX = sendPhoneObj.getTransformTo(null).getTranslation().x;
  267. tipPosY = sendPhoneObj.getTransformTo(null).getTranslation().y - ScreenUtil.getInstance().setHeight(90);
  268. tipStatus = false;
  269. });
  270. }else{
  271. setState(() {
  272. tipStatus = true;
  273. });
  274. }
  275. // print(tipWidth);
  276. // print(tipHeight);
  277. // print(tipPosX);
  278. // print(tipPosY);
  279. }
  280. }),
  281. onEditingComplete: () {
  282. setState(() {
  283. FocusScope.of(context).requestFocus(FocusNode());
  284. tipStatus = true;
  285. });
  286. },
  287. ),
  288. ),
  289. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  290. ],
  291. )
  292. )
  293. ],
  294. ),
  295. )
  296. ),
  297. Expanded(
  298. flex: 0,
  299. child: _underLine()
  300. )
  301. ],
  302. )
  303. );
  304. }
  305. Widget _contentWiget(String key, String value,[bool keyboardType=false]) {//false是数字键盘
  306. return Padding(
  307. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  308. child: Column(
  309. children: < Widget > [
  310. SizedBox(
  311. height: ScreenUtil.getInstance().setHeight(89),
  312. child: Center(
  313. child: Row(
  314. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  315. children: < Widget > [
  316. Expanded(
  317. flex: 0,
  318. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  319. ),
  320. Expanded(
  321. child: Row(
  322. mainAxisAlignment: MainAxisAlignment.end,
  323. children: < Widget > [
  324. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  325. SizedBox(
  326. width: ScreenUtil.getInstance().setWidth(500),
  327. child: TextField(
  328. keyboardType:keyboardType?TextInputType.text:TextInputType.number,
  329. textAlign: TextAlign.end,
  330. decoration: InputDecoration(
  331. border: InputBorder.none
  332. ),
  333. ),
  334. ),
  335. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  336. ],
  337. )
  338. )
  339. ],
  340. ),
  341. )
  342. ),
  343. Expanded(
  344. flex: 0,
  345. child: _underLine()
  346. )
  347. ],
  348. )
  349. );
  350. }
  351. Widget _cityWiget(String key, String value, BuildContext context) {
  352. return
  353. GestureDetector(
  354. child: Padding(
  355. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  356. child: Column(
  357. children: < Widget > [
  358. SizedBox(
  359. height: ScreenUtil.getInstance().setHeight(89),
  360. child: Center(
  361. child: Row(
  362. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  363. children: < Widget > [
  364. Expanded(
  365. flex: 0,
  366. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  367. ),
  368. Expanded(
  369. child: Row(
  370. mainAxisAlignment: MainAxisAlignment.end,
  371. children: < Widget > [
  372. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  373. SizedBox(
  374. width: ScreenUtil.getInstance().setWidth(500),
  375. child: Text(value, textAlign: TextAlign.end, overflow: TextOverflow.ellipsis, )
  376. ),
  377. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  378. ],
  379. )
  380. )
  381. ],
  382. ),
  383. )
  384. ),
  385. Expanded(
  386. flex: 0,
  387. child: _underLine()
  388. )
  389. ],
  390. )
  391. ),
  392. onTap: () {
  393. getCity(context).then((resp) {
  394. if (resp == null) {
  395. return;
  396. }
  397. setState(() {
  398. sendInfo['address'] = resp.provinceName + ' ' + resp.cityName + ' ' + ' ' + resp.areaName;
  399. });
  400. //print(value);
  401. });
  402. },
  403. );
  404. }
  405. Widget _lastContentWiget(String key, String value) {
  406. return Padding(
  407. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  408. child: SizedBox(
  409. height: ScreenUtil.getInstance().setHeight(89),
  410. child: Center(
  411. child: Row(
  412. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  413. children: < Widget > [
  414. Expanded(
  415. flex: 0,
  416. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  417. ),
  418. Expanded(
  419. child: Row(
  420. mainAxisAlignment: MainAxisAlignment.end,
  421. children: < Widget > [
  422. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  423. SizedBox(
  424. width: ScreenUtil.getInstance().setWidth(500),
  425. child: TextField(
  426. //keyboardType: TextInputType.number,
  427. textAlign: TextAlign.end,
  428. decoration: InputDecoration(
  429. border: InputBorder.none
  430. ),
  431. ),
  432. ),
  433. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  434. ],
  435. )
  436. )
  437. ],
  438. ),
  439. )
  440. )
  441. );
  442. }
  443. Widget _descWidget(String str) {
  444. return
  445. Container(
  446. padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
  447. //child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  448. child: TextField(
  449. maxLines: 3,
  450. decoration: InputDecoration(
  451. border: InputBorder.none,
  452. hintText: "请输入备注内容"
  453. ),
  454. ),
  455. );
  456. }
  457. Widget _submitBtn() {
  458. return GestureDetector(
  459. child: Container(
  460. margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
  461. height: ScreenUtil.getInstance().setHeight(88),
  462. decoration: BoxDecoration(
  463. borderRadius: BorderRadius.all(Radius.circular(4)),
  464. color: Color.fromRGBO(37, 102, 242, 1),
  465. ),
  466. child: Center(
  467. child: Text("提交", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Colors.white), ),
  468. ),
  469. ),
  470. onTap: () {
  471. print('提交');
  472. },
  473. );
  474. }
  475. Future getCity(context) async {
  476. Result result = await CityPickers.showCityPicker(
  477. context: context,
  478. );
  479. return result;
  480. }
  481. Widget _tipItem() {
  482. return Container(
  483. child: Column(
  484. children: < Widget > [
  485. Container(
  486. height: ScreenUtil.getInstance().setHeight(89),
  487. child: Center(
  488. child: Row(
  489. mainAxisAlignment: MainAxisAlignment.start,
  490. children: < Widget > [
  491. Padding(
  492. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(50)),
  493. child: Text("15901462275", style: TextStyle(
  494. fontSize: ScreenUtil.getInstance().setSp(28),
  495. color: Color.fromRGBO(74, 74, 74, 1)
  496. ), )
  497. ),
  498. SizedBox(
  499. width: ScreenUtil.getInstance().setWidth(185),
  500. child: Text('WX11042',
  501. textAlign: TextAlign.left,
  502. style: TextStyle(
  503. fontSize: ScreenUtil.getInstance().setSp(28),
  504. color: Color.fromRGBO(155,155,155,1)
  505. ),),
  506. ),
  507. Text('天华盛业',
  508. textAlign: TextAlign.left,
  509. overflow: TextOverflow.ellipsis,
  510. style: TextStyle(
  511. fontSize: ScreenUtil.getInstance().setSp(28),
  512. color: Color.fromRGBO(155,155,155,1)
  513. ),
  514. )
  515. ],
  516. ),
  517. ),
  518. ),
  519. _underLine()
  520. ],
  521. ),
  522. );
  523. }
  524. }