order_taking_page.dart 11 KB

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