my_page.dart 13 KB

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