order_taking_page.dart 12 KB

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