send_express_page.dart 19 KB

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