my_page.dart 15 KB

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