order_taking_page.dart 12 KB

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