blue_location_mixin.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import 'package:flutter_blue_plus/flutter_blue_plus.dart';
  2. import 'package:geolocator/geolocator.dart';
  3. import 'package:get/get_state_manager/src/simple/get_controllers.dart';
  4. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  5. import 'package:fis_common/logger/logger.dart';
  6. mixin BluetoothAndLocationMixin on GetxController {
  7. Future<bool> checkBluetoothIsOpen() async {
  8. BluetoothAdapterState flutterBlue =
  9. await FlutterBluePlus.adapterState.first;
  10. logger.i(
  11. "BluetoothAndLocationMixin checkBluetoothIsOpen result:${flutterBlue.toString()}");
  12. if (flutterBlue != BluetoothAdapterState.on) {
  13. PromptBox.toast('蓝牙未开启');
  14. return false;
  15. }
  16. return true;
  17. }
  18. Future<bool> checkLocationIsOpen() async {
  19. bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
  20. logger.i(
  21. "BluetoothAndLocationMixin checkLocationIsOpen result:$serviceEnabled");
  22. if (!serviceEnabled) {
  23. PromptBox.toast('位置信息服务未开启');
  24. return false;
  25. }
  26. return true;
  27. }
  28. /// 检查设备连接环境(蓝牙等服务是否开启)
  29. Future<bool> checkDeviceConnectEnv() async {
  30. bool passed = await checkBluetoothIsOpen();
  31. if (passed) {
  32. passed = await checkLocationIsOpen();
  33. }
  34. return passed;
  35. }
  36. }