my_page.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. List printTypeList = ["全部", "配件商", "修理厂", "司机", "货物", "货物外", "不打印"];
  28. static
  29. var printTypeMap = {
  30. "全部": "1",
  31. "配件商": "2",
  32. "修理厂": "3",
  33. "司机": "4",
  34. "货物": "5",
  35. "货物外": "6",
  36. "不打印": "7",
  37. };
  38. static
  39. var printTypeMapSecond = {
  40. "1": "全部",
  41. "2": "配件商",
  42. "3": "修理厂",
  43. "4": "司机",
  44. "5": "货物",
  45. "6": "货物外",
  46. "7": "不打印",
  47. };
  48. String printType = '全部';
  49. @override
  50. bool get wantKeepAlive => true;
  51. @override
  52. void initState() {
  53. super.initState();
  54. getStationList().then((resp) {
  55. if (isNotError(context, resp)) {
  56. stationObj = Station.fromJson(resp.data);
  57. getKey('stationId').then((value) {
  58. List < String > tempList = [];
  59. for (int i = 0; i < stationObj.data.length; i++) {
  60. tempList.add(stationObj.data[i].name.toString());
  61. if (stationObj.data[i].id.toString() == value) {
  62. _siteName = stationObj.data[i].name.toString();
  63. }
  64. }
  65. getKey('nickName').then((value) {
  66. setState(() {
  67. stationList = tempList;
  68. name = value;
  69. });
  70. });
  71. getKey('printType').then((value) {
  72. printType = printTypeMapSecond[value];
  73. });
  74. });
  75. }
  76. });
  77. bluetooth.getEchannel().receiveBroadcastStream().listen(onEvent, onError: onError);
  78. }
  79. onEvent(Object obj) {
  80. print(obj.toString());
  81. }
  82. onError(Object obj) {
  83. print(obj.toString());
  84. }
  85. @override
  86. Widget build(BuildContext context) {
  87. return Container(
  88. child: Scaffold(
  89. appBar: AppBar(
  90. elevation: 0,
  91. title: Text('我的',
  92. style: TextStyle(
  93. fontSize: ScreenUtil.getInstance().setSp(36)
  94. ), ),
  95. centerTitle: true,
  96. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  97. actions: < Widget > [
  98. InkWell(
  99. child: Container(
  100. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
  101. child: Center(
  102. child: Text('退出'),
  103. )
  104. ),
  105. onTap: () {
  106. showDialog < Null > (
  107. context: context, //BuildContext对象
  108. barrierDismissible: false,
  109. builder: (BuildContext context) {
  110. return new LoadingDialog( //调用对话框
  111. text: '确认退出?', childCallback: (val) {
  112. if (val) {
  113. clearKey();
  114. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
  115. return LoginPage();
  116. }));
  117. } else {
  118. return;
  119. }
  120. },
  121. );
  122. });
  123. },
  124. )
  125. ],
  126. ),
  127. body: Container(
  128. color: Color.fromRGBO(246, 246, 254, 1),
  129. child: Column(
  130. children: < Widget > [
  131. _avatarWidget(),
  132. _funWrapWidget(check, context),
  133. ],
  134. ),
  135. ),
  136. )
  137. );
  138. }
  139. Widget _avatarWidget() {
  140. return Container(
  141. color: Color.fromRGBO(64, 98, 254, 1),
  142. padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(59), 0, ScreenUtil.getInstance().setHeight(67), ),
  143. child: Column(
  144. children: < Widget > [
  145. Center(
  146. child: Padding(
  147. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setWidth(24), ),
  148. child: ClipOval(
  149. child: Image.asset('lib/images/icon_logo.png',
  150. fit: BoxFit.cover,
  151. width: ScreenUtil.getInstance().setWidth(120),
  152. height: ScreenUtil.getInstance().setWidth(120), ),
  153. )
  154. )
  155. ),
  156. Center(child: Text(name, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(255, 255, 255, 1)), ), )
  157. ],
  158. ),
  159. );
  160. }
  161. Widget _funWrapWidget(bool check, BuildContext context) {
  162. return Container(
  163. padding: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
  164. child: Column(
  165. children: < Widget > [
  166. _switchSite(context),
  167. _passWordWidget(),
  168. _linkPrint(check),
  169. _printType(),
  170. //_quitWidget(context)
  171. ],
  172. ),
  173. );
  174. }
  175. Widget _switchSite(BuildContext context) {
  176. return InkWell(
  177. child: Container(
  178. height: ScreenUtil.getInstance().setHeight(90),
  179. color: Colors.white,
  180. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  181. child: Column(
  182. children: < Widget > [
  183. Expanded(
  184. child: Center(
  185. child: Row(
  186. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  187. children: < Widget > [
  188. Expanded(
  189. child: Row(
  190. mainAxisAlignment: MainAxisAlignment.start,
  191. children: < Widget > [
  192. Padding(
  193. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(22)),
  194. child: Image.asset('lib/images/icon_zhandianss.png',
  195. width: ScreenUtil.getInstance().setWidth(30),
  196. height: ScreenUtil.getInstance().setHeight(34),
  197. )
  198. ),
  199. Text('站点切换', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  200. ],
  201. ),
  202. ),
  203. Expanded(
  204. child: Row(
  205. mainAxisAlignment: MainAxisAlignment.end,
  206. children: < Widget > [
  207. Text(_siteName, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)), ),
  208. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
  209. ],
  210. ),
  211. ),
  212. ],
  213. ),
  214. ),
  215. ),
  216. Expanded(
  217. flex: 0,
  218. child: _underLine(),
  219. )
  220. ],
  221. )
  222. ),
  223. onTap: () {
  224. // showDialog < Null > (
  225. // context: context, //BuildContext对象
  226. // barrierDismissible: false,
  227. // builder: (BuildContext context) {
  228. // return SiteDialog( //调用对话框
  229. // );
  230. // });
  231. showPickerModal(context, 'station');
  232. },
  233. );
  234. }
  235. showPickerModal(BuildContext context, String type) {
  236. var list;
  237. if (type == 'station') {
  238. list = stationList;
  239. } else if (type == 'printType') {
  240. list = printTypeList;
  241. }
  242. new Picker(
  243. adapter: PickerDataAdapter < String > (pickerdata: list),
  244. height: ScreenUtil.getInstance().setHeight(450),
  245. confirmText: '确定',
  246. confirmTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(64, 98, 254, 1)),
  247. cancelText: '取消',
  248. cancelTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)),
  249. headercolor: Color.fromRGBO(245, 245, 245, 1),
  250. itemExtent: ScreenUtil.getInstance().setHeight(80),
  251. textStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(42, 42, 42, 1)),
  252. changeToFirst: true,
  253. hideHeader: false,
  254. onConfirm: (Picker picker, List value) {
  255. if (type == 'station') {
  256. setState(() {
  257. _siteName = stationObj.data[value[0]].name;
  258. });
  259. setKey('stationId', stationObj.data[value[0]].id.toString());
  260. } else if (type == "printType") {
  261. setState(() {
  262. printType = printTypeList[value[0]];
  263. });
  264. setKey('printType', printTypeMap[printTypeList[value[0]]]);
  265. getKey('printType').then((value) {
  266. print(value);
  267. });
  268. }
  269. }
  270. ).showModal(this.context); //_scaffoldKey.currentState);
  271. }
  272. Widget _underLine() {
  273. return Container(
  274. height: ScreenUtil.getInstance().setHeight(1),
  275. color: Color.fromRGBO(223, 223, 223, 1),
  276. );
  277. }
  278. Widget _passWordWidget() {
  279. return
  280. GestureDetector(
  281. child: Container(
  282. height: ScreenUtil.getInstance().setHeight(90),
  283. color: Colors.white,
  284. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  285. child: Column(
  286. children: < Widget > [
  287. Expanded(
  288. child: Center(
  289. child: Row(
  290. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  291. children: < Widget > [
  292. Expanded(
  293. child: Row(
  294. mainAxisAlignment: MainAxisAlignment.start,
  295. children: < Widget > [
  296. Padding(
  297. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(22)),
  298. child: Image.asset('lib/images/icon_mimas.png',
  299. width: ScreenUtil.getInstance().setWidth(30),
  300. height: ScreenUtil.getInstance().setHeight(34),
  301. )
  302. ),
  303. Text('修改密码', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  304. ],
  305. ),
  306. ),
  307. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
  308. ],
  309. ),
  310. ),
  311. )
  312. ],
  313. )
  314. ),
  315. onTap: () {
  316. Navigator.push(context, MaterialPageRoute(builder: (context) {
  317. return RevisePasswordPage();
  318. }));
  319. },
  320. );
  321. }
  322. Widget _linkPrint(bool check) {
  323. return Container(
  324. height: ScreenUtil.getInstance().setHeight(90),
  325. color: Colors.white,
  326. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  327. margin: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
  328. child: Column(
  329. children: < Widget > [
  330. Expanded(
  331. child: Center(
  332. child: Row(
  333. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  334. children: < Widget > [
  335. Expanded(
  336. child: Row(
  337. mainAxisAlignment: MainAxisAlignment.start,
  338. children: < Widget > [
  339. Padding(
  340. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(22)),
  341. child: Image.asset('lib/images/icon_dayinji.png',
  342. width: ScreenUtil.getInstance().setWidth(30),
  343. height: ScreenUtil.getInstance().setHeight(34),
  344. )
  345. ),
  346. Text('打印机连接', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  347. ],
  348. ),
  349. ),
  350. Switch(
  351. value: this.check,
  352. activeColor: Colors.blue,
  353. onChanged: (bool val) {
  354. bluetooth.isBTDevice().then((resp) {
  355. if (resp) {
  356. bluetooth.isEnableBluetooth().then((bool resp) {
  357. this.setState(() {
  358. this.check = resp;
  359. });
  360. bluetooth.scanBT(); //
  361. });
  362. }
  363. });
  364. },
  365. )
  366. ],
  367. ),
  368. ),
  369. ),
  370. _underLine()
  371. ],
  372. )
  373. );
  374. }
  375. Widget _printType() {
  376. return InkWell(
  377. child: Container(
  378. height: ScreenUtil.getInstance().setHeight(90),
  379. color: Colors.white,
  380. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  381. child: Column(
  382. children: < Widget > [
  383. Expanded(
  384. child: Center(
  385. child: Row(
  386. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  387. children: < Widget > [
  388. Expanded(
  389. child: Row(
  390. mainAxisAlignment: MainAxisAlignment.start,
  391. children: < Widget > [
  392. Padding(
  393. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(22)),
  394. child: Image.asset('lib/images/icon_dayinji.png',
  395. width: ScreenUtil.getInstance().setWidth(30),
  396. height: ScreenUtil.getInstance().setHeight(34),
  397. )
  398. ),
  399. Text('打印类型', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  400. ],
  401. ),
  402. ),
  403. Row(
  404. mainAxisAlignment: MainAxisAlignment.end,
  405. children: < Widget > [
  406. Text(printType, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)), ),
  407. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
  408. ],
  409. )
  410. ],
  411. ),
  412. ),
  413. )
  414. ],
  415. )
  416. ),
  417. onTap: () {
  418. showPickerModal(context, 'printType');
  419. },
  420. );
  421. }
  422. Widget _quitWidget(BuildContext context) {
  423. return InkWell(
  424. child: Container(
  425. height: ScreenUtil.getInstance().setHeight(90),
  426. color: Colors.white,
  427. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(30), 0, 0, 0),
  428. margin: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
  429. child: Column(
  430. children: < Widget > [
  431. Expanded(
  432. child: Center(
  433. child: Row(
  434. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  435. children: < Widget > [
  436. Text('退出', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  437. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1))
  438. ],
  439. ),
  440. ),
  441. )
  442. ],
  443. )
  444. ),
  445. onTap: () {
  446. showDialog < Null > (
  447. context: context, //BuildContext对象
  448. barrierDismissible: false,
  449. builder: (BuildContext context) {
  450. return new LoadingDialog( //调用对话框
  451. text: '确认退出?', childCallback: (val) {
  452. if (val) {
  453. clearKey();
  454. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
  455. return LoginPage();
  456. }));
  457. } else {
  458. return;
  459. }
  460. },
  461. );
  462. });
  463. },
  464. );
  465. }
  466. }