my_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'my_page/revise_password_page.dart';
  4. import 'package:flutter_picker/flutter_picker.dart';
  5. import '../showDialog.dart';
  6. import '../login_page.dart';
  7. import '../util/api.dart';
  8. import '../util/models.dart';
  9. import '../util/session.dart';
  10. import '../util/util.dart';
  11. class MyPage extends StatefulWidget {
  12. final Widget child;
  13. MyPage({
  14. Key key,
  15. this.child
  16. }): super(key: key);
  17. _MyPageState createState() => _MyPageState();
  18. }
  19. class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
  20. bool check = false;
  21. String _siteName = "请选择站点";
  22. List < String > stationList = [];
  23. Station stationObj;
  24. String name = '物流';
  25. @override
  26. bool get wantKeepAlive => true;
  27. @override
  28. void initState() {
  29. super.initState();
  30. getStationList().then((resp) {
  31. if (isNotError(context, resp)) {
  32. stationObj = Station.fromJson(resp.data);
  33. List < String > tempList = [];
  34. for (int i = 0; i < stationObj.data.length; i++) {
  35. tempList.add(stationObj.data[i].name.toString());
  36. }
  37. getKey('nickName').then((value) {
  38. setState(() {
  39. stationList = tempList;
  40. name = value;
  41. _siteName = tempList[0];
  42. });
  43. });
  44. print(stationObj.data[0].id.toString());
  45. setKey('stationId', stationObj.data[0].id.toString());
  46. }
  47. });
  48. }
  49. @override
  50. Widget build(BuildContext context) {
  51. return Container(
  52. child: Scaffold(
  53. appBar: AppBar(
  54. elevation: 0,
  55. title: Text('我的',
  56. style: TextStyle(
  57. fontSize: ScreenUtil.getInstance().setSp(36)
  58. ), ),
  59. centerTitle: true,
  60. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  61. ),
  62. body: Container(
  63. color: Color.fromRGBO(246, 246, 254, 1),
  64. child: Column(
  65. children: < Widget > [
  66. _avatarWidget(),
  67. _funWrapWidget(check, context),
  68. ],
  69. ),
  70. ),
  71. )
  72. );
  73. }
  74. Widget _avatarWidget() {
  75. return Container(
  76. color: Color.fromRGBO(64, 98, 254, 1),
  77. padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(59), 0, ScreenUtil.getInstance().setHeight(67), ),
  78. child: Column(
  79. children: < Widget > [
  80. Center(
  81. child: Padding(
  82. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setWidth(24), ),
  83. child: ClipOval(
  84. child: Image.asset('lib/images/icon_logo.png',
  85. fit: BoxFit.cover,
  86. width: ScreenUtil.getInstance().setWidth(120),
  87. height: ScreenUtil.getInstance().setWidth(120), ),
  88. )
  89. )
  90. ),
  91. Center(child: Text(name, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(255, 255, 255, 1)), ), )
  92. ],
  93. ),
  94. );
  95. }
  96. Widget _funWrapWidget(bool check, BuildContext context) {
  97. return Container(
  98. padding: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
  99. child: Column(
  100. children: < Widget > [
  101. _switchSite(context),
  102. _passWordWidget(),
  103. _linkPrint(check),
  104. _quitWidget(context)
  105. ],
  106. ),
  107. );
  108. }
  109. Widget _switchSite(BuildContext context) {
  110. return InkWell(
  111. child: Container(
  112. height: ScreenUtil.getInstance().setHeight(90),
  113. color: Colors.white,
  114. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  115. child: Column(
  116. children: < Widget > [
  117. Expanded(
  118. child: Center(
  119. child: Row(
  120. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  121. children: < Widget > [
  122. Expanded(
  123. child: Row(
  124. mainAxisAlignment: MainAxisAlignment.start,
  125. children: < Widget > [
  126. Padding(
  127. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(22)),
  128. child: Image.asset('lib/images/icon_zhandianss.png',
  129. width: ScreenUtil.getInstance().setWidth(30),
  130. height: ScreenUtil.getInstance().setHeight(34),
  131. )
  132. ),
  133. Text('站点切换', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  134. ],
  135. ),
  136. ),
  137. Expanded(
  138. child: Row(
  139. mainAxisAlignment: MainAxisAlignment.end,
  140. children: < Widget > [
  141. Text(_siteName, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)), ),
  142. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
  143. ],
  144. ),
  145. ),
  146. ],
  147. ),
  148. ),
  149. ),
  150. Expanded(
  151. flex: 0,
  152. child: _underLine(),
  153. )
  154. ],
  155. )
  156. ),
  157. onTap: () {
  158. // showDialog < Null > (
  159. // context: context, //BuildContext对象
  160. // barrierDismissible: false,
  161. // builder: (BuildContext context) {
  162. // return SiteDialog( //调用对话框
  163. // );
  164. // });
  165. showPickerModal(context);
  166. },
  167. );
  168. }
  169. showPickerModal(BuildContext context) {
  170. new Picker(
  171. adapter: PickerDataAdapter < String > (pickerdata: stationList),
  172. height: ScreenUtil.getInstance().setHeight(450),
  173. confirmText: '确定',
  174. confirmTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(64, 98, 254, 1)),
  175. cancelText: '取消',
  176. cancelTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)),
  177. headercolor: Color.fromRGBO(245, 245, 245, 1),
  178. itemExtent: ScreenUtil.getInstance().setHeight(80),
  179. textStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(42, 42, 42, 1)),
  180. changeToFirst: true,
  181. hideHeader: false,
  182. onConfirm: (Picker picker, List value) {
  183. setState(() {
  184. _siteName = stationObj.data[value[0]].name;
  185. });
  186. setKey('stationId', stationObj.data[value[0]].id.toString());
  187. }
  188. ).showModal(this.context); //_scaffoldKey.currentState);
  189. }
  190. Widget _underLine() {
  191. return Container(
  192. height: ScreenUtil.getInstance().setHeight(1),
  193. color: Color.fromRGBO(223, 223, 223, 1),
  194. );
  195. }
  196. Widget _passWordWidget() {
  197. return
  198. GestureDetector(
  199. child: Container(
  200. height: ScreenUtil.getInstance().setHeight(90),
  201. color: Colors.white,
  202. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  203. child: Column(
  204. children: < Widget > [
  205. Expanded(
  206. child: Center(
  207. child: Row(
  208. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  209. children: < Widget > [
  210. Expanded(
  211. child: Row(
  212. mainAxisAlignment: MainAxisAlignment.start,
  213. children: < Widget > [
  214. Padding(
  215. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(22)),
  216. child: Image.asset('lib/images/icon_mimas.png',
  217. width: ScreenUtil.getInstance().setWidth(30),
  218. height: ScreenUtil.getInstance().setHeight(34),
  219. )
  220. ),
  221. Text('修改密码', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  222. ],
  223. ),
  224. ),
  225. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
  226. ],
  227. ),
  228. ),
  229. )
  230. ],
  231. )
  232. ),
  233. onTap: () {
  234. Navigator.push(context, MaterialPageRoute(builder: (context) {
  235. return RevisePasswordPage();
  236. }));
  237. },
  238. );
  239. }
  240. Widget _linkPrint(bool check) {
  241. return Container(
  242. height: ScreenUtil.getInstance().setHeight(90),
  243. color: Colors.white,
  244. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  245. margin: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
  246. child: Column(
  247. children: < Widget > [
  248. Expanded(
  249. child: Center(
  250. child: Row(
  251. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  252. children: < Widget > [
  253. Expanded(
  254. child: Row(
  255. mainAxisAlignment: MainAxisAlignment.start,
  256. children: < Widget > [
  257. Padding(
  258. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(22)),
  259. child: Image.asset('lib/images/icon_dayinji.png',
  260. width: ScreenUtil.getInstance().setWidth(30),
  261. height: ScreenUtil.getInstance().setHeight(34),
  262. )
  263. ),
  264. Text('打印机连接', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  265. ],
  266. ),
  267. ),
  268. Switch(
  269. value: this.check,
  270. activeColor: Colors.blue,
  271. onChanged: (bool val) {
  272. this.setState(() {
  273. this.check = val;
  274. });
  275. print('check:${this.check}');
  276. },
  277. )
  278. ],
  279. ),
  280. ),
  281. )
  282. ],
  283. )
  284. );
  285. }
  286. Widget _quitWidget(BuildContext context) {
  287. return InkWell(
  288. child: Container(
  289. height: ScreenUtil.getInstance().setHeight(90),
  290. color: Colors.white,
  291. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  292. margin: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
  293. child: Column(
  294. children: < Widget > [
  295. Expanded(
  296. child: Center(
  297. child: Row(
  298. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  299. children: < Widget > [
  300. Text('退出', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  301. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
  302. ],
  303. ),
  304. ),
  305. )
  306. ],
  307. )
  308. ),
  309. onTap: () {
  310. showDialog < Null > (
  311. context: context, //BuildContext对象
  312. barrierDismissible: false,
  313. builder: (BuildContext context) {
  314. return new LoadingDialog( //调用对话框
  315. text: '确认退出?', childCallback: (val) {
  316. if (val) {
  317. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
  318. return LoginPage();
  319. }));
  320. } else {
  321. return;
  322. }
  323. },
  324. );
  325. });
  326. },
  327. );
  328. }
  329. }
  330. // //打印机弹出层
  331. // class PrintDialog extends Dialog {
  332. // PrintDialog({
  333. // Key key,
  334. // }): super(key: key);
  335. // }