my_page.dart 12 KB

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