order_taking_page.dart 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. class OrderTakingPage extends StatefulWidget {
  6. OrderTakingPage({
  7. Key key
  8. }): super(key: key);
  9. _OrderTakingPageState createState() => _OrderTakingPageState();
  10. }
  11. class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeepAliveClientMixin {
  12. List listObj=[];
  13. @override
  14. void initState() {
  15. // TODO: implement initState
  16. super.initState();
  17. getOrderList().then((resp){
  18. setState(() {
  19. listObj = resp.orderList;
  20. });
  21. //print(listObj[0].id);
  22. });
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. super.build(context);
  27. return Container(
  28. child: Scaffold(
  29. appBar: AppBar(
  30. title: Text('接单', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
  31. centerTitle: true,
  32. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  33. actions: < Widget > [
  34. Container(
  35. child: PopupMenuButton<String>(
  36. icon: Icon(Icons.add_circle_outline),
  37. offset: Offset(0, 60),
  38. padding: EdgeInsets.zero,
  39. //child: IconButton(icon: Image.asset('lib/images/icon_shaixuan.png', scale: 1.8, ),onPressed: (){},),
  40. itemBuilder: (BuildContext context)=><PopupMenuEntry<String>>[
  41. PopupMenuItem<String>(
  42. child:Text("hahahahahh"),
  43. ),
  44. PopupMenuDivider(height: 1.0),
  45. PopupMenuItem<String>(
  46. child:Text("hahahahahh"),
  47. ),
  48. PopupMenuDivider(height: 1.0),
  49. PopupMenuItem<String>(
  50. child:Text("hahahahahh"),
  51. ),
  52. PopupMenuDivider(height: 1.0),
  53. ]
  54. )
  55. ),
  56. ],
  57. ),
  58. body: Container(
  59. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), 0),
  60. decoration: BoxDecoration(
  61. color: Color.fromRGBO(246, 246, 254, 1)
  62. ),
  63. child: ListView.builder(
  64. itemCount: listObj.length,
  65. itemBuilder: (BuildContext context,int index){
  66. return OrderCard(order:listObj[index]);
  67. },
  68. ),
  69. )
  70. ),
  71. );
  72. }
  73. @override
  74. bool get wantKeepAlive => true;
  75. }
  76. class OrderCard extends StatefulWidget {
  77. final OrderList order;
  78. OrderCard({Key key,@required this.order}): super(key: key);
  79. _OrderCardState createState() => _OrderCardState();
  80. }
  81. class _OrderCardState extends State < OrderCard > {
  82. @override
  83. Widget build(BuildContext context) {
  84. return Card(
  85. color: Colors.white,
  86. elevation: 3.0,
  87. child: Column(
  88. children: < Widget > [
  89. OrderCardContainer(order: widget.order)
  90. ],
  91. ),
  92. );
  93. }
  94. }
  95. class OrderCardContainer extends StatefulWidget {
  96. final OrderList order;
  97. OrderCardContainer({Key key, @required this.order}): super(key: key);
  98. _OrderCardContainerState createState() => _OrderCardContainerState();
  99. }
  100. class _OrderCardContainerState extends State < OrderCardContainer > with SingleTickerProviderStateMixin {
  101. Animation < double > animation;
  102. AnimationController controller;
  103. String str="联系方式";
  104. bool animationStatus =true;
  105. @override
  106. initState() {
  107. super.initState();
  108. controller = new AnimationController(
  109. duration: const Duration(milliseconds: 200), vsync: this);
  110. animation = new Tween(begin: 0.0, end: 230.0).animate(controller);
  111. animation.addStatusListener((status){
  112. if (status == AnimationStatus.completed) {
  113. //动画执行结束时反向执行动画
  114. setState(() {
  115. animationStatus = false;
  116. str="收起";
  117. });
  118. } else if (status == AnimationStatus.dismissed) {
  119. //动画恢复到初始状态时执行动画(正向)
  120. setState(() {
  121. animationStatus=true;
  122. str="联系方式";
  123. });
  124. }
  125. });
  126. }
  127. @override
  128. Widget build(BuildContext context) {
  129. return Container(
  130. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), 0),
  131. child: Column(
  132. children: < Widget > [
  133. orderNoRow(widget.order.orderNo,widget.order.createTime),
  134. orderAddress(widget.order.startAddress,widget.order.endAddress),
  135. orderItem('货物名称', widget.order.itemName, 15),
  136. orderItem('货物件数', '${widget.order.itemNo}件', 30),
  137. orderCutLine(),
  138. orderBtn(animationStatus,controller,str),
  139. AnimatedOpen(animation: animation,openInfo: widget.order,)
  140. ],
  141. ),
  142. );
  143. }
  144. dispose() {
  145. //路由销毁时需要释放动画资源
  146. controller.dispose();
  147. super.dispose();
  148. }
  149. }
  150. Widget orderBtn(bool animationStatus,AnimationController controller,String str){
  151. return Container(
  152. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  153. child: Row(
  154. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  155. children: < Widget > [
  156. GestureDetector(
  157. child: Container(
  158. width: ScreenUtil.getInstance().setWidth(100),
  159. height: ScreenUtil.getInstance().setHeight(48),
  160. color: Colors.white,
  161. child: Center(
  162. child: Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1)), ),
  163. )
  164. ),
  165. onTap: () {
  166. if (animationStatus) {
  167. //动画恢复到初始状态时执行动画(正向)
  168. controller.forward();
  169. } else{
  170. //动画执行结束时反向执行动画
  171. controller.reverse();
  172. }
  173. },
  174. ),
  175. GestureDetector(
  176. child: Container(
  177. width: ScreenUtil.getInstance().setWidth(94),
  178. height: ScreenUtil.getInstance().setWidth(48),
  179. decoration: BoxDecoration(
  180. color: Color.fromRGBO(252, 97, 128, 1),
  181. borderRadius: BorderRadius.all(Radius.circular(4.0))
  182. ),
  183. child: Center(
  184. child: Text("接单", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Colors.white), ),
  185. ),
  186. ),
  187. onTap: () {
  188. print("22222");
  189. },
  190. )
  191. ],
  192. )
  193. );
  194. }
  195. class AnimatedOpen extends AnimatedWidget {
  196. final OrderList openInfo;
  197. AnimatedOpen({
  198. Key key,
  199. Animation < double > animation,
  200. @required this.openInfo
  201. }): super(key: key, listenable: animation);
  202. Widget build(BuildContext context) {
  203. final Animation < double > animation = listenable;
  204. return Container(
  205. height: ScreenUtil.getInstance().setHeight(animation.value),
  206. child: orderDetailInfo(openInfo),
  207. );
  208. }
  209. }
  210. Widget orderNoRow(int orderNo,String createTime) { //订单号及时间
  211. return Container(
  212. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
  213. child: Row(
  214. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  215. children: < Widget > [
  216. Text("订单号:${orderNo}", style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  217. Text(createTime, style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  218. ],
  219. ),
  220. );
  221. }
  222. Widget orderAddress(String startAddress,String endAddress) { //运送路线
  223. return Container(
  224. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  225. child: Row(children: < Widget > [
  226. Text('${startAddress} ---> ${endAddress}', style: TextStyle(color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(30)), ),
  227. ], )
  228. );
  229. }
  230. Widget orderCutLine() { //分割线
  231. return Container(
  232. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  233. height: ScreenUtil.getInstance().setHeight(1),
  234. color: Color.fromRGBO(223, 223, 223, 1),
  235. );
  236. }
  237. Widget orderDetailInfo(OrderList obj) {//卡片展开信息
  238. return Container(
  239. child: Wrap(
  240. children: < Widget > [
  241. orderCutLine(),
  242. orderPhone('发件电话', obj.sendPhone, 15),
  243. orderItem('发件地址', obj.sendAddress, 30),
  244. orderPhone('收件电话', obj.getPhone, 15),
  245. orderItem('收件地址', obj.getAddress, 30),
  246. ],
  247. )
  248. );
  249. }
  250. Widget orderItem(String key, String value, int marginBottom) {//货物名称,件数
  251. return Container(
  252. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(marginBottom)),
  253. child: Row(children: < Widget > [
  254. Text('${key}:${value}', style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  255. ], )
  256. );
  257. }
  258. Widget orderPhone(String key, String value, int marginBottom) {
  259. return Container(
  260. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(marginBottom)),
  261. child: Row(children: < Widget > [
  262. Text('${key}:', style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  263. Text('${value}', style: TextStyle(color: Color.fromRGBO(64, 98, 254, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
  264. ], )
  265. );
  266. }