order_taking_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:url_launcher/url_launcher.dart';
  4. import '../util/api.dart';
  5. import '../util/models.dart';
  6. import '../showDialog.dart';
  7. import '../util/session.dart';
  8. class OrderTakingPage extends StatefulWidget {
  9. OrderTakingPage({
  10. Key key
  11. }): super(key: key);
  12. _OrderTakingPageState createState() => _OrderTakingPageState();
  13. }
  14. class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeepAliveClientMixin {
  15. ScrollController _scrollController = ScrollController(); //初始化滚动轴监控对象
  16. List listObj = [];
  17. List lineList=[];
  18. List<PopupMenuEntry<String>> widgets=[];
  19. @override
  20. void initState() {
  21. super.initState();
  22. getOrderList().then((resp) {
  23. setState(() {
  24. listObj = resp.orderList;
  25. });
  26. });
  27. getKey('stationId').then((value){
  28. getLineFromStation(value).then((resp){
  29. if(resp.success && resp.code==1){
  30. setState(() {
  31. lineList = resp.data;
  32. });
  33. List<PopupMenuEntry<String>> tempWidgets = [];
  34. for(int i=0;i<lineList.length;i++){
  35. tempWidgets.add(
  36. PopupMenuItem<String>(
  37. value: lineList[i].name,
  38. child: Text(lineList[i].name,)
  39. )
  40. );
  41. }
  42. print(lineList.length);
  43. setState(() {
  44. widgets =tempWidgets;
  45. });
  46. print(widgets.length);
  47. }
  48. });
  49. });
  50. _scrollController.addListener(() {
  51. if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
  52. print("滑到底部了");
  53. // getOrderList().then((resp) {
  54. // setState(() {
  55. // listObj.addAll(resp.orderList);
  56. // });
  57. // });
  58. }
  59. //print(_scrollController.position.pixels);
  60. });
  61. }
  62. @override
  63. bool get wantKeepAlive => true;
  64. @override
  65. void dispose() {
  66. super.dispose();
  67. _scrollController.dispose();
  68. print('接单页listView滚动监听销毁了');
  69. }
  70. @override
  71. Widget build(BuildContext context) {
  72. super.build(context);
  73. return Container(
  74. child: Scaffold(
  75. appBar: AppBar(
  76. title: Text('接单', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
  77. centerTitle: true,
  78. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  79. actions: < Widget > [
  80. Container(
  81. child: PopupMenuButton(
  82. icon: Icon(Icons.add_circle_outline),
  83. offset: Offset(0, 60),
  84. padding: EdgeInsets.zero,
  85. //child: IconButton(icon: Image.asset('lib/images/icon_shaixuan.png', scale: 1.8, ),onPressed: (){},),
  86. itemBuilder: (BuildContext context){
  87. return widgets;
  88. // <PopupMenuEntry<String>>[
  89. // PopupMenuItem<String>(
  90. // value: '1111',
  91. // child: Text('lineList[0].name',)
  92. // )
  93. // ];
  94. }
  95. )
  96. ),
  97. ],
  98. ),
  99. body: Container(
  100. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), 0),
  101. decoration: BoxDecoration(
  102. color: Color.fromRGBO(246, 246, 254, 1)
  103. ),
  104. child: RefreshIndicator( //下拉刷新组件
  105. onRefresh: _onRefresh, //回调方法
  106. child: ListView.builder(
  107. controller: _scrollController,
  108. itemCount: listObj.length + 1,
  109. itemBuilder: (BuildContext context, int index) { //itemBuilder实际上就是一个map的循环
  110. if (index < listObj.length) {
  111. return OrderCardContainer(order: listObj[index], index: index, callback: (val) => deleteOrder(val));
  112. }
  113. return _getMoreWidget();
  114. },
  115. )
  116. ),
  117. )
  118. ),
  119. );
  120. }
  121. Widget _getMoreWidget() {
  122. return Center(
  123. child: Padding(
  124. padding: EdgeInsets.all(10.0),
  125. child: Row(
  126. mainAxisAlignment: MainAxisAlignment.center,
  127. crossAxisAlignment: CrossAxisAlignment.center,
  128. children: < Widget > [
  129. Text(
  130. '加载中...',
  131. style: TextStyle(fontSize: 16.0),
  132. ),
  133. Container(
  134. width: ScreenUtil.getInstance().setWidth(50),
  135. height: ScreenUtil.getInstance().setHeight(50),
  136. child: CircularProgressIndicator()
  137. )
  138. ],
  139. ),
  140. ),
  141. );
  142. }
  143. Future < Null > _onRefresh() async {
  144. await getOrderList().then((resp) {
  145. setState(() {
  146. listObj = resp.orderList;
  147. });
  148. });
  149. }
  150. void deleteOrder(val) {
  151. setState(() {
  152. listObj.removeAt(val);
  153. if (listObj.length < 4) {
  154. getOrderList().then((resp) {
  155. setState(() {
  156. listObj.addAll(resp.orderList);
  157. });
  158. });
  159. }
  160. });
  161. }
  162. }
  163. class OrderCardContainer extends StatefulWidget {
  164. final OrderList order;
  165. final int index;
  166. final callback;
  167. OrderCardContainer({
  168. Key key,
  169. @required this.order,
  170. @required this.index,
  171. @required this.callback
  172. }): super(key: key);
  173. _OrderCardContainerState createState() => _OrderCardContainerState();
  174. }
  175. class _OrderCardContainerState extends State < OrderCardContainer > with SingleTickerProviderStateMixin {
  176. Animation < double > animation;
  177. AnimationController controller;
  178. String str = "联系方式";
  179. bool animationStatus = true;
  180. @override
  181. initState() {
  182. super.initState();
  183. controller = new AnimationController(
  184. duration: const Duration(milliseconds: 200), vsync: this);
  185. animation = new Tween(begin: 0.0, end: 230.0).animate(controller);
  186. animation.addStatusListener((status) {
  187. if (status == AnimationStatus.completed) {
  188. //动画执行结束时反向执行动画
  189. setState(() {
  190. animationStatus = false;
  191. str = "收起";
  192. });
  193. } else if (status == AnimationStatus.dismissed) {
  194. //动画恢复到初始状态时执行动画(正向)
  195. setState(() {
  196. animationStatus = true;
  197. str = "联系方式";
  198. });
  199. }
  200. });
  201. }
  202. @override
  203. Widget build(BuildContext context) {
  204. return Card(
  205. color: Colors.white,
  206. elevation: 3.0,
  207. child: Container(
  208. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), 0),
  209. child: Column(
  210. children: < Widget > [
  211. orderNoRow(widget.order.orderNo, widget.order.createTime),
  212. orderAddress(widget.order.startAddress, widget.order.endAddress),
  213. orderItem('货物名称', widget.order.itemName, 15),
  214. orderItem('货物件数', '${widget.order.itemNo}件', 30),
  215. orderCutLine(),
  216. orderBtn(context, animationStatus, controller, str),
  217. AnimatedOpen(animation: animation, openInfo: widget.order, )
  218. ],
  219. ),
  220. )
  221. );
  222. }
  223. dispose() {
  224. //路由销毁时需要释放动画资源
  225. controller.dispose();
  226. super.dispose();
  227. }
  228. Widget orderBtn(BuildContext context, bool animationStatus, AnimationController controller, String str) {
  229. return Container(
  230. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  231. child: Row(
  232. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  233. children: < Widget > [
  234. GestureDetector(
  235. child: Container(
  236. width: ScreenUtil.getInstance().setWidth(100),
  237. height: ScreenUtil.getInstance().setHeight(48),
  238. color: Colors.white,
  239. child: Center(
  240. child: Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1)), ),
  241. )
  242. ),
  243. onTap: () {
  244. if (animationStatus) {
  245. //动画恢复到初始状态时执行动画(正向)
  246. controller.forward();
  247. } else {
  248. //动画执行结束时反向执行动画
  249. controller.reverse();
  250. }
  251. },
  252. ),
  253. GestureDetector(
  254. child: Container(
  255. width: ScreenUtil.getInstance().setWidth(94),
  256. height: ScreenUtil.getInstance().setWidth(48),
  257. decoration: BoxDecoration(
  258. color: Color.fromRGBO(252, 97, 128, 1),
  259. borderRadius: BorderRadius.all(Radius.circular(4.0))
  260. ),
  261. child: Center(
  262. child: Text("接单", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Colors.white), ),
  263. ),
  264. ),
  265. onTap: () {
  266. getKey('stationId').then((value){
  267. print(value);
  268. });
  269. showDialog < Null > (
  270. context: context, //BuildContext对象
  271. barrierDismissible: false,
  272. builder: (BuildContext context) {
  273. return new LoadingDialog( //调用对话框
  274. text: '是否确认接单', childCallback: (val) {
  275. if (val) {
  276. widget.callback(widget.index);
  277. } else {
  278. return;
  279. }
  280. },
  281. );
  282. });
  283. },
  284. )
  285. ],
  286. )
  287. );
  288. }
  289. }
  290. class AnimatedOpen extends AnimatedWidget {
  291. final OrderList openInfo;
  292. AnimatedOpen({
  293. Key key,
  294. Animation < double > animation,
  295. @required this.openInfo
  296. }): super(key: key, listenable: animation);
  297. Widget build(BuildContext context) {
  298. final Animation < double > animation = listenable;
  299. return Container(
  300. height: ScreenUtil.getInstance().setHeight(animation.value),
  301. child: orderDetailInfo(openInfo),
  302. );
  303. }
  304. }
  305. Widget orderNoRow(int orderNo, String createTime) { //订单号及时间
  306. return Container(
  307. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  308. child: Row(
  309. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  310. children: < Widget > [
  311. Text("订单号:${orderNo}", style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  312. Text(createTime, style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  313. ],
  314. ),
  315. );
  316. }
  317. Widget orderAddress(String startAddress, String endAddress) { //运送路线
  318. return Container(
  319. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  320. child: Row(children: < Widget > [
  321. Text('${startAddress} ---> ${endAddress}', style: TextStyle(color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(30)), ),
  322. ], )
  323. );
  324. }
  325. Widget orderCutLine() { //分割线
  326. return Container(
  327. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  328. height: ScreenUtil.getInstance().setHeight(1),
  329. color: Color.fromRGBO(223, 223, 223, 1),
  330. );
  331. }
  332. Widget orderDetailInfo(OrderList obj) { //卡片展开信息
  333. return Container(
  334. child: Wrap(
  335. children: < Widget > [
  336. orderCutLine(),
  337. orderPhone('发件电话', obj.sendPhone, 15),
  338. orderItem('发件地址', obj.sendAddress, 30),
  339. orderPhone('收件电话', obj.getPhone, 15),
  340. orderItem('收件地址', obj.getAddress, 30),
  341. ],
  342. )
  343. );
  344. }
  345. Widget orderItem(String key, String value, int marginBottom) { //货物名称,件数
  346. return Container(
  347. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(marginBottom)),
  348. child: Row(children: < Widget > [
  349. Text('${key}:${value}', style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  350. ], )
  351. );
  352. }
  353. Widget orderPhone(String key, String value, int marginBottom) {
  354. return InkWell(
  355. child: Container(
  356. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(marginBottom)),
  357. child: Row(children: < Widget > [
  358. Text('${key}:', style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  359. Text('${value}', style: TextStyle(color: Color.fromRGBO(64, 98, 254, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  360. ], )
  361. ),
  362. onLongPress: () async {
  363. String phone = 'tel:${value}';
  364. print(phone);
  365. if(await canLaunch(phone)){
  366. await (launch(phone));
  367. }else{
  368. throw 'Could not launch $value';
  369. }
  370. },
  371. );
  372. }