my_page.dart 12 KB

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