blue_location_mixin.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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([bool closeToast = false]) async {
  8. BluetoothAdapterState flutterBlue =
  9. await FlutterBluePlus.adapterState.first;
  10. logger.i(
  11. "BluetoothAndLocationMixin checkBluetoothIsOpen result:${flutterBlue.toString()}");
  12. if (flutterBlue != BluetoothAdapterState.on) {
  13. if (!closeToast) {
  14. PromptBox.toast('蓝牙未开启');
  15. }
  16. return false;
  17. }
  18. return true;
  19. }
  20. Future<bool> checkLocationIsOpen([bool closeToast = false]) async {
  21. bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
  22. logger.i(
  23. "BluetoothAndLocationMixin checkLocationIsOpen result:$serviceEnabled");
  24. if (!serviceEnabled) {
  25. if (!closeToast) {
  26. PromptBox.toast('位置信息服务未开启');
  27. }
  28. return false;
  29. }
  30. return true;
  31. }
  32. /// 检查设备连接环境(蓝牙等服务是否开启)
  33. Future<bool> checkDeviceConnectEnv() async {
  34. bool passed = await checkBluetoothIsOpen();
  35. if (passed) {
  36. passed = await checkLocationIsOpen();
  37. }
  38. return passed;
  39. }
  40. }