123456789101112131415161718192021222324252627282930313233343536373839 |
- 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<bool> 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<bool> checkLocationIsOpen() async {
- bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
- logger.i(
- "BluetoothAndLocationMixin checkLocationIsOpen result:$serviceEnabled");
- if (!serviceEnabled) {
- PromptBox.toast('位置信息服务未开启');
- return false;
- }
- return true;
- }
- /// 检查设备连接环境(蓝牙等服务是否开启)
- Future<bool> checkDeviceConnectEnv() async {
- bool passed = await checkBluetoothIsOpen();
- if (passed) {
- passed = await checkLocationIsOpen();
- }
- return passed;
- }
- }
|