|
@@ -20,6 +20,7 @@ class _TrackPageState extends State<TrackPage> {
|
|
|
List<dynamic> contactTraces = [];
|
|
|
List<dynamic> contactTimes = [];
|
|
|
List<dynamic> contactLocations = [];
|
|
|
+ FlutterBlue flutterBlue = FlutterBlue.instance;
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
@@ -85,26 +86,7 @@ class _TrackPageState extends State<TrackPage> {
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
- Padding(
|
|
|
- padding: EdgeInsets.only(bottom: 200.0),
|
|
|
- child: RaisedButton(
|
|
|
- shape: RoundedRectangleBorder(
|
|
|
- borderRadius: BorderRadius.circular(20.0)),
|
|
|
- elevation: 5.0,
|
|
|
- color: Colors.deepPurple[400],
|
|
|
- onPressed: () async {
|
|
|
- startTrack();
|
|
|
- },
|
|
|
- child: const Text(
|
|
|
- '开始追踪',
|
|
|
- style: TextStyle(
|
|
|
- fontSize: 20.0,
|
|
|
- fontWeight: FontWeight.bold,
|
|
|
- color: Colors.white,
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
+ buildStartButton(),
|
|
|
Expanded(
|
|
|
flex: 2,
|
|
|
child: Padding(
|
|
@@ -113,11 +95,9 @@ class _TrackPageState extends State<TrackPage> {
|
|
|
itemBuilder: (context, index) {
|
|
|
return ContactCard(
|
|
|
imagePath: 'assets/images/head.jpg',
|
|
|
- email: contactTraces[index],
|
|
|
- infection: 'Not-Infected',
|
|
|
+ infection: '健康',
|
|
|
contactUsername: contactTraces[index],
|
|
|
contactTime: contactTimes[index],
|
|
|
- contactLocation: contactLocations[index],
|
|
|
);
|
|
|
},
|
|
|
itemCount: contactTraces.length,
|
|
@@ -128,7 +108,81 @@ class _TrackPageState extends State<TrackPage> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- void startTrack() async {
|
|
|
+ StreamBuilder<bool> buildStartButton() {
|
|
|
+ return StreamBuilder<bool>(
|
|
|
+ stream: flutterBlue.isScanning,
|
|
|
+ initialData: false,
|
|
|
+ builder: (context, snapshot) {
|
|
|
+ if (snapshot.data) {
|
|
|
+ return Padding(
|
|
|
+ padding: EdgeInsets.only(bottom: 200.0),
|
|
|
+ child: RaisedButton(
|
|
|
+ shape: RoundedRectangleBorder(
|
|
|
+ borderRadius: BorderRadius.circular(20.0)),
|
|
|
+ elevation: 5.0,
|
|
|
+ color: Colors.red,
|
|
|
+ onPressed: () async {
|
|
|
+ startTrack(snapshot.data);
|
|
|
+ },
|
|
|
+ child: const Text(
|
|
|
+ '停止追踪',
|
|
|
+ style: TextStyle(
|
|
|
+ fontSize: 20.0,
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ color: Colors.white,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return Padding(
|
|
|
+ padding: EdgeInsets.only(bottom: 200.0),
|
|
|
+ child: RaisedButton(
|
|
|
+ shape: RoundedRectangleBorder(
|
|
|
+ borderRadius: BorderRadius.circular(20.0)),
|
|
|
+ elevation: 5.0,
|
|
|
+ color: Colors.deepPurple[400],
|
|
|
+ onPressed: () async {
|
|
|
+ startTrack(snapshot.data);
|
|
|
+ },
|
|
|
+ child: const Text(
|
|
|
+ '开始追踪',
|
|
|
+ style: TextStyle(
|
|
|
+ fontSize: 20.0,
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ color: Colors.white,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void startTrack(bool flag) async {
|
|
|
+ if (flag) {
|
|
|
+ flutterBlue.stopScan();
|
|
|
+ } else {
|
|
|
+ AppUtil.buildToast("正在搜索附近的人...");
|
|
|
+ flutterBlue.startScan(timeout: const Duration(seconds: 4));
|
|
|
+ // 扫描周围蓝牙设备
|
|
|
+ // List<BluetoothService> services = await device.discoverServices();
|
|
|
+ var subscription = flutterBlue.scanResults.listen((scanResult) {
|
|
|
+ for (ScanResult scan in scanResult) {
|
|
|
+ BluetoothDevice device = scan.device;
|
|
|
+ print("------------------------------" +
|
|
|
+ '${device.name} found! rssi: ${scan.rssi}dBm' +
|
|
|
+ device.id.toString());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 上传周边设备到服务器
|
|
|
+
|
|
|
+ // 循环对每个设备检测安全性
|
|
|
+
|
|
|
+ //更新结果
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
// try {
|
|
|
// bool a = await Nearby().startAdvertising(
|
|
|
// loggedInUser.email,
|
|
@@ -148,9 +202,8 @@ class _TrackPageState extends State<TrackPage> {
|
|
|
// }
|
|
|
|
|
|
discovery();
|
|
|
- AppUtil.buildToast("正在搜索附近的人...");
|
|
|
AppUtil.buildToast("追踪用户状态中...");
|
|
|
}
|
|
|
|
|
|
- void discovery() {}
|
|
|
+ void discovery() async {}
|
|
|
}
|