send_express_page.dart 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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'],true),
  140. _contentWiget('企业名称', str['name'],true),
  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'],true),
  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"],true),
  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. if (tab == 'sendPhone') {
  243. if(value.length>=4){
  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. }else{
  253. setState(() {
  254. tipStatus = true;
  255. });
  256. }
  257. // print(tipWidth);
  258. // print(tipHeight);
  259. // print(tipPosX);
  260. // print(tipPosY);
  261. } else if (tab == 'getPhone') {
  262. if(value.length>=4){
  263. RenderObject sendPhoneObj = _getPhoneKey.currentContext.findRenderObject();
  264. setState(() {
  265. tipWidth = sendPhoneObj.paintBounds.size.width;
  266. tipHeight = sendPhoneObj.paintBounds.size.height;
  267. tipPosX = sendPhoneObj.getTransformTo(null).getTranslation().x;
  268. tipPosY = sendPhoneObj.getTransformTo(null).getTranslation().y - ScreenUtil.getInstance().setHeight(90);
  269. tipStatus = false;
  270. });
  271. }else{
  272. setState(() {
  273. tipStatus = true;
  274. });
  275. }
  276. // print(tipWidth);
  277. // print(tipHeight);
  278. // print(tipPosX);
  279. // print(tipPosY);
  280. }
  281. }),
  282. onEditingComplete: () {
  283. setState(() {
  284. FocusScope.of(context).requestFocus(FocusNode());
  285. tipStatus = true;
  286. });
  287. },
  288. ),
  289. ),
  290. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  291. ],
  292. )
  293. )
  294. ],
  295. ),
  296. )
  297. ),
  298. Expanded(
  299. flex: 0,
  300. child: _underLine()
  301. )
  302. ],
  303. )
  304. );
  305. }
  306. Widget _contentWiget(String key, String value,[bool keyboardType=false]) {//false是数字键盘
  307. return Padding(
  308. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  309. child: Column(
  310. children: < Widget > [
  311. SizedBox(
  312. height: ScreenUtil.getInstance().setHeight(89),
  313. child: Center(
  314. child: Row(
  315. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  316. children: < Widget > [
  317. Expanded(
  318. flex: 0,
  319. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  320. ),
  321. Expanded(
  322. child: Row(
  323. mainAxisAlignment: MainAxisAlignment.end,
  324. children: < Widget > [
  325. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  326. SizedBox(
  327. width: ScreenUtil.getInstance().setWidth(500),
  328. child: TextField(
  329. keyboardType:keyboardType?TextInputType.text:TextInputType.number,
  330. textAlign: TextAlign.end,
  331. decoration: InputDecoration(
  332. border: InputBorder.none
  333. ),
  334. ),
  335. ),
  336. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  337. ],
  338. )
  339. )
  340. ],
  341. ),
  342. )
  343. ),
  344. Expanded(
  345. flex: 0,
  346. child: _underLine()
  347. )
  348. ],
  349. )
  350. );
  351. }
  352. Widget _cityWiget(String key, String value, BuildContext context) {
  353. return
  354. GestureDetector(
  355. child: Padding(
  356. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  357. child: Column(
  358. children: < Widget > [
  359. SizedBox(
  360. height: ScreenUtil.getInstance().setHeight(89),
  361. child: Center(
  362. child: Row(
  363. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  364. children: < Widget > [
  365. Expanded(
  366. flex: 0,
  367. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  368. ),
  369. Expanded(
  370. child: Row(
  371. mainAxisAlignment: MainAxisAlignment.end,
  372. children: < Widget > [
  373. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  374. SizedBox(
  375. width: ScreenUtil.getInstance().setWidth(500),
  376. child: Text(value, textAlign: TextAlign.end, overflow: TextOverflow.ellipsis, )
  377. ),
  378. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  379. ],
  380. )
  381. )
  382. ],
  383. ),
  384. )
  385. ),
  386. Expanded(
  387. flex: 0,
  388. child: _underLine()
  389. )
  390. ],
  391. )
  392. ),
  393. onTap: () {
  394. getCity(context).then((resp) {
  395. if (resp == null) {
  396. return;
  397. }
  398. setState(() {
  399. sendInfo['address'] = resp.provinceName + ' ' + resp.cityName + ' ' + ' ' + resp.areaName;
  400. });
  401. //print(value);
  402. });
  403. },
  404. );
  405. }
  406. Widget _lastContentWiget(String key, String value) {
  407. return Padding(
  408. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  409. child: SizedBox(
  410. height: ScreenUtil.getInstance().setHeight(89),
  411. child: Center(
  412. child: Row(
  413. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  414. children: < Widget > [
  415. Expanded(
  416. flex: 0,
  417. child: Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  418. ),
  419. Expanded(
  420. child: Row(
  421. mainAxisAlignment: MainAxisAlignment.end,
  422. children: < Widget > [
  423. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  424. SizedBox(
  425. width: ScreenUtil.getInstance().setWidth(500),
  426. child: TextField(
  427. //keyboardType: TextInputType.number,
  428. textAlign: TextAlign.end,
  429. decoration: InputDecoration(
  430. border: InputBorder.none
  431. ),
  432. ),
  433. ),
  434. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  435. ],
  436. )
  437. )
  438. ],
  439. ),
  440. )
  441. )
  442. );
  443. }
  444. Widget _descWidget(String str) {
  445. return
  446. Container(
  447. padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
  448. //child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  449. child: TextField(
  450. maxLines: 3,
  451. decoration: InputDecoration(
  452. border: InputBorder.none,
  453. hintText: "请输入备注内容"
  454. ),
  455. ),
  456. );
  457. }
  458. Widget _submitBtn() {
  459. return GestureDetector(
  460. child: Container(
  461. margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
  462. height: ScreenUtil.getInstance().setHeight(88),
  463. decoration: BoxDecoration(
  464. borderRadius: BorderRadius.all(Radius.circular(4)),
  465. color: Color.fromRGBO(37, 102, 242, 1),
  466. ),
  467. child: Center(
  468. child: Text("提交", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Colors.white), ),
  469. ),
  470. ),
  471. onTap: () {
  472. print('提交');
  473. },
  474. );
  475. }
  476. Future getCity(context) async {
  477. Result result = await CityPickers.showCityPicker(
  478. context: context,
  479. );
  480. return result;
  481. }
  482. Widget _tipItem() {
  483. return Container(
  484. child: Column(
  485. children: < Widget > [
  486. Container(
  487. height: ScreenUtil.getInstance().setHeight(89),
  488. child: Center(
  489. child: Row(
  490. mainAxisAlignment: MainAxisAlignment.start,
  491. children: < Widget > [
  492. Padding(
  493. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(50)),
  494. child: Text("15901462275", style: TextStyle(
  495. fontSize: ScreenUtil.getInstance().setSp(28),
  496. color: Color.fromRGBO(74, 74, 74, 1)
  497. ), )
  498. ),
  499. SizedBox(
  500. width: ScreenUtil.getInstance().setWidth(185),
  501. child: Text('WX11042',
  502. textAlign: TextAlign.left,
  503. style: TextStyle(
  504. fontSize: ScreenUtil.getInstance().setSp(28),
  505. color: Color.fromRGBO(155,155,155,1)
  506. ),),
  507. ),
  508. Text('天华盛业',
  509. textAlign: TextAlign.left,
  510. overflow: TextOverflow.ellipsis,
  511. style: TextStyle(
  512. fontSize: ScreenUtil.getInstance().setSp(28),
  513. color: Color.fromRGBO(155,155,155,1)
  514. ),
  515. )
  516. ],
  517. ),
  518. ),
  519. ),
  520. _underLine()
  521. ],
  522. ),
  523. );
  524. }
  525. }