send_express_page.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. _tipItem(),
  120. _tipItem(),
  121. _tipItem(),
  122. _tipItem(),
  123. _tipItem(),
  124. _tipItem(),
  125. _tipItem(),
  126. _tipItem(),
  127. _tipItem(),
  128. _tipItem(),
  129. ],
  130. ),
  131. ),
  132. )
  133. )
  134. ],
  135. ),
  136. resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误
  137. ),
  138. );
  139. }
  140. Widget _sendInfo(Map str, BuildContext context) {
  141. return Container(
  142. color: Colors.white,
  143. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  144. child: Column(
  145. children: < Widget > [
  146. _titleWidget(str['icon'], str['title']),
  147. _underLine(),
  148. _inputWiget('电话', 'sendPhone'),
  149. _contentWiget('企业编码', str['code']),
  150. _contentWiget('企业名称', str['name']),
  151. _cityWiget('城市/区域', str['address'], context),
  152. _lastContentWiget('详细地址', str['addressDetail'])
  153. ],
  154. )
  155. );
  156. }
  157. Widget _getInfo(Map str) {
  158. return Container(
  159. color: Colors.white,
  160. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  161. child: Column(
  162. children: < Widget > [
  163. _titleWidget(str['icon'], str['title']),
  164. _underLine(),
  165. _contentWiget('企业名称', str['name']),
  166. _inputWiget('电话', 'getPhone'),
  167. _cityWiget('城市/区域', str['address'], context),
  168. _lastContentWiget('详细地址', str['addressDetail'])
  169. ],
  170. )
  171. );
  172. }
  173. Widget _itemInfoWidget(Map _itemInfo) {
  174. return Container(
  175. child: Container(
  176. color: Colors.white,
  177. child: Column(
  178. crossAxisAlignment: CrossAxisAlignment.start,
  179. children: < Widget > [
  180. _titleWidget(_itemInfo['icon'], "货物信息"),
  181. _underLine(),
  182. _contentWiget("货物名称", _itemInfo["itemName"]),
  183. _contentWiget("数量", _itemInfo["itemNo"]),
  184. _contentWiget("运费", _itemInfo["expressPrice"]),
  185. _contentWiget("代收", _itemInfo["collectionPrice"]),
  186. _contentWiget("保价", _itemInfo["supportPrice"]),
  187. _contentWiget("重量", _itemInfo["weight"]),
  188. _descWidget(_itemInfo['itemDesc'])
  189. ],
  190. ),
  191. )
  192. );
  193. }
  194. Widget _titleWidget(String iconUrl, String str) {
  195. return Container(
  196. height: ScreenUtil.getInstance().setHeight(90),
  197. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  198. child: Center(
  199. child: Row(
  200. mainAxisAlignment: MainAxisAlignment.start,
  201. children: < Widget > [
  202. Padding(
  203. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
  204. child: Image.asset(
  205. iconUrl,
  206. width: ScreenUtil.getInstance().setWidth(40),
  207. height: ScreenUtil.getInstance().setHeight(40),
  208. )
  209. ),
  210. Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
  211. ],
  212. ),
  213. ),
  214. );
  215. }
  216. Widget _underLine() {
  217. return Container(
  218. color: Color.fromRGBO(223, 223, 223, 1),
  219. height: ScreenUtil.getInstance().setHeight(1),
  220. );
  221. }
  222. Widget _inputWiget(String key, String tab) {
  223. return Padding(
  224. key: tab == 'sendPhone' ? _sendPhoneKey : _getPhoneKey,
  225. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  226. child: Column(
  227. children: < Widget > [
  228. SizedBox(
  229. height: ScreenUtil.getInstance().setHeight(89),
  230. child: Center(
  231. child: Row(
  232. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  233. children: < Widget > [
  234. Expanded(
  235. flex: 0,
  236. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  237. ),
  238. Expanded(
  239. child: Row(
  240. mainAxisAlignment: MainAxisAlignment.end,
  241. children: < Widget > [
  242. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  243. SizedBox(
  244. width: ScreenUtil.getInstance().setWidth(500),
  245. child: TextField(
  246. keyboardType: TextInputType.number,
  247. textAlign: TextAlign.end,
  248. decoration: InputDecoration(
  249. border: InputBorder.none
  250. ),
  251. onChanged: ((value) {
  252. print("onchange 了");
  253. if (tab == 'sendPhone') {
  254. RenderObject sendPhoneObj = _sendPhoneKey.currentContext.findRenderObject();
  255. setState(() {
  256. tipWidth = sendPhoneObj.paintBounds.size.width;
  257. tipHeight = sendPhoneObj.paintBounds.size.height;
  258. tipPosX = sendPhoneObj.getTransformTo(null).getTranslation().x;
  259. tipPosY = sendPhoneObj.getTransformTo(null).getTranslation().y - ScreenUtil.getInstance().setHeight(90);
  260. tipStatus = false;
  261. });
  262. print(tipWidth);
  263. print(tipHeight);
  264. print(tipPosX);
  265. print(tipPosY);
  266. } else if (tab == 'getPhone') {
  267. RenderObject sendPhoneObj = _getPhoneKey.currentContext.findRenderObject();
  268. setState(() {
  269. tipWidth = sendPhoneObj.paintBounds.size.width;
  270. tipHeight = sendPhoneObj.paintBounds.size.height;
  271. tipPosX = sendPhoneObj.getTransformTo(null).getTranslation().x;
  272. tipPosY = sendPhoneObj.getTransformTo(null).getTranslation().y - ScreenUtil.getInstance().setHeight(90);
  273. tipStatus = false;
  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) {
  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: 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. }