|
|
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
import 'my_page/revise_password_page.dart';
|
|
|
import 'package:flutter_picker/flutter_picker.dart';
|
|
|
+import 'dart:convert';
|
|
|
import '../util/bluetooth_utils.dart';
|
|
|
import '../showDialog.dart';
|
|
|
import '../login_page.dart';
|
|
|
@@ -29,8 +30,8 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
Station stationObj;
|
|
|
String name = '物流';
|
|
|
BluetoothUtils bluetooth = BluetoothUtils();
|
|
|
- List<String> btList = [];
|
|
|
- Set<String> btSet = Set();
|
|
|
+ List < BtInfoObj > btList = [];
|
|
|
+ Set < BtInfoObj > btSet = Set();
|
|
|
List printTypeList = ["全部", "配件商", "修理厂", "司机", "货物", "货物外", "不打印"];
|
|
|
static
|
|
|
var printTypeMap = {
|
|
|
@@ -84,17 +85,32 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
});
|
|
|
|
|
|
bluetooth.getEchannel().receiveBroadcastStream().listen(onEvent, onError: onError);
|
|
|
+ getKey('check').then((value) {
|
|
|
+ if (value == null) {
|
|
|
+ setState(() {
|
|
|
+ check = false;
|
|
|
+ });
|
|
|
+ } else if (value == 'false') {
|
|
|
+ setState(() {
|
|
|
+ check = false;
|
|
|
+ });
|
|
|
+ } else if (value == 'true') {
|
|
|
+ setState(() {
|
|
|
+ check = true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ print(check);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
onEvent(Object obj) {
|
|
|
- setState(() {
|
|
|
- if(obj.toString().indexOf('||')!=-1){
|
|
|
- int index = obj.toString().indexOf('||');
|
|
|
- String temp = obj.toString().substring(0,index);
|
|
|
- btSet.add(temp);
|
|
|
- btList =btSet.toList();
|
|
|
- }
|
|
|
- });
|
|
|
+ if (obj.toString().indexOf('||') != -1) { //过滤开始搜索和结束搜索
|
|
|
+ BtInfoObj tempObj = BtInfoObj(name: obj.toString(), showLoadStauts: false, connectStatus: false);
|
|
|
+ btSet.add(tempObj);
|
|
|
+ setState(() {
|
|
|
+ btList = btSet.toList();
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
onError(Object obj) {
|
|
|
@@ -148,7 +164,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
child: Column(
|
|
|
children: < Widget > [
|
|
|
_avatarWidget(),
|
|
|
- _funWrapWidget(check, context),
|
|
|
+ _funWrapWidget(context),
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
@@ -180,14 +196,14 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _funWrapWidget(bool check, BuildContext context) {
|
|
|
+ Widget _funWrapWidget(BuildContext context) {
|
|
|
return Container(
|
|
|
padding: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(20)),
|
|
|
child: Column(
|
|
|
children: < Widget > [
|
|
|
_switchSite(context),
|
|
|
_passWordWidget(),
|
|
|
- _linkPrint(check),
|
|
|
+ _linkPrint(),
|
|
|
_printType(),
|
|
|
_btList()
|
|
|
],
|
|
|
@@ -346,7 +362,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _linkPrint(bool check) {
|
|
|
+ Widget _linkPrint() {
|
|
|
return Container(
|
|
|
height: ScreenUtil.getInstance().setHeight(90),
|
|
|
color: Colors.white,
|
|
|
@@ -375,30 +391,31 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
),
|
|
|
),
|
|
|
Switch(
|
|
|
- value: this.check,
|
|
|
+ value: check,
|
|
|
activeColor: Colors.blue,
|
|
|
onChanged: (bool val) {
|
|
|
- if(val){
|
|
|
+ if (val) {
|
|
|
bluetooth.isBTDevice().then((resp) {
|
|
|
- if (resp) {
|
|
|
- bluetooth.isEnableBluetooth().then((bool resp) {
|
|
|
- this.setState(() {
|
|
|
- this.check = resp;
|
|
|
+ if (resp) {
|
|
|
+ bluetooth.isEnableBluetooth().then((bool resp) { //打开蓝牙
|
|
|
+ setState(() {
|
|
|
+ check = true;
|
|
|
+ });
|
|
|
+ setKey('check', 'true');
|
|
|
+ bluetooth.scanBT(); //
|
|
|
});
|
|
|
- bluetooth.scanBT(); //
|
|
|
- });
|
|
|
|
|
|
- }
|
|
|
- });
|
|
|
- }else{
|
|
|
- bluetooth.disConnnectBT();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ bluetooth.disConnnectBT(); //关闭蓝牙
|
|
|
setState(() {
|
|
|
- this.check = val;
|
|
|
+ check = false;
|
|
|
btList.clear();
|
|
|
- btSet.clear();
|
|
|
});
|
|
|
+ setKey('check', 'false');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
)
|
|
|
],
|
|
|
@@ -463,19 +480,21 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
return Container(
|
|
|
height: ScreenUtil.getInstance().setHeight(350),
|
|
|
padding: EdgeInsets.all(ScreenUtil.getInstance().setHeight(30)),
|
|
|
- child: ListView.builder(
|
|
|
- itemCount:btList.length,
|
|
|
+ child: (btList.length > 0 && check==true) ? ListView.builder(
|
|
|
+ itemCount: btList.length,
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
-
|
|
|
- return _btItem(btList[index]);
|
|
|
-
|
|
|
-
|
|
|
+ return _btItem(btList[index], index);
|
|
|
},
|
|
|
- )
|
|
|
+ ) : check==true?_searchBt():Center()
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _btItem(String name) {
|
|
|
+ Widget _btItem(BtInfoObj obj, int index) {
|
|
|
+ print(obj.name);
|
|
|
+ int tempIndex = obj.name.indexOf('||');
|
|
|
+ String name = obj.name.substring(0, tempIndex);
|
|
|
+ String btAddress = obj.name.substring(tempIndex + 2, obj.name.length);
|
|
|
+ print(btAddress);
|
|
|
return InkWell(
|
|
|
child: Padding(
|
|
|
padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
|
|
|
@@ -483,29 +502,41 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
children: < Widget > [
|
|
|
Text(name),
|
|
|
+ obj.showLoadStauts ? SizedBox(
|
|
|
+ width: ScreenUtil.getInstance().setWidth(35),
|
|
|
+ height: ScreenUtil.getInstance().setHeight(35),
|
|
|
+ child: Image.asset('lib/images/loading.gif'),
|
|
|
+ ) :
|
|
|
CircleAvatar(
|
|
|
- backgroundColor: Colors.grey,
|
|
|
+ backgroundColor: obj.connectStatus ? Color.fromRGBO(64, 98, 254, 1) : Colors.grey,
|
|
|
radius: 6,
|
|
|
)
|
|
|
],
|
|
|
)
|
|
|
),
|
|
|
- onTap: (){
|
|
|
- print('链接');
|
|
|
+ onTap: () {
|
|
|
+ //bluetooth.connnectBT(btAddress);
|
|
|
+ setState(() {
|
|
|
+ btList[index].showLoadStauts = true;
|
|
|
+ });
|
|
|
},
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _searchBt(){
|
|
|
- return InkWell(
|
|
|
- child: Center(
|
|
|
- child: Container(
|
|
|
- width: 160,
|
|
|
- height: 30,
|
|
|
- color: Colors.blue,
|
|
|
- child: Text('扫描中'),
|
|
|
- ),
|
|
|
+ Widget _searchBt() {
|
|
|
+ return Center(
|
|
|
+ child: Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ children: < Widget > [
|
|
|
+ Text('正在搜索...'),
|
|
|
+ SizedBox(
|
|
|
+ width: ScreenUtil.getInstance().setWidth(45),
|
|
|
+ height: ScreenUtil.getInstance().setHeight(45),
|
|
|
+ child: Image.asset('lib/images/loading.gif'),
|
|
|
+ )
|
|
|
+ ],
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
}
|