my_page.dart 17 KB

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