import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:geolocator/geolocator.dart'; import 'package:get/get_state_manager/src/simple/get_controllers.dart'; import 'package:vitalapp/architecture/utils/prompt_box.dart'; import 'package:fis_common/logger/logger.dart'; mixin BluetoothAndLocationMixin on GetxController { Future checkBluetoothIsOpen() async { BluetoothAdapterState flutterBlue = await FlutterBluePlus.adapterState.first; logger.i( "BluetoothAndLocationMixin checkBluetoothIsOpen result:${flutterBlue.toString()}"); if (flutterBlue != BluetoothAdapterState.on) { PromptBox.toast('蓝牙未开启'); return false; } return true; } Future checkLocationIsOpen() async { bool serviceEnabled = await Geolocator.isLocationServiceEnabled(); logger.i( "BluetoothAndLocationMixin checkLocationIsOpen result:$serviceEnabled"); if (!serviceEnabled) { PromptBox.toast('位置信息服务未开启'); return false; } return true; } /// 检查设备连接环境(蓝牙等服务是否开启) Future checkDeviceConnectEnv() async { bool passed = await checkBluetoothIsOpen(); if (passed) { passed = await checkLocationIsOpen(); } return passed; } }