app.dart 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'dart:io';
  2. import 'package:farmer_client/models/entities/person.dart';
  3. import 'package:get/get.dart';
  4. import 'package:location/location.dart';
  5. import '../services/user.dart';
  6. import '../utils/location.dart';
  7. class AppController extends GetxController {
  8. // 有了这句, 可以直接 AppController.t 调用
  9. static AppController t = Get.find();
  10. final user = Rx<Person>(Person());
  11. final location = Rxn<LocationData>();
  12. final testInt = 1.obs;
  13. @override
  14. void onInit() {
  15. super.onInit();
  16. // 尝试获取 location
  17. requireLocation().then((loc) async {
  18. var _data = await loc.getLocation();
  19. location(_data);
  20. // 监听位置变化
  21. loc.onLocationChanged.listen((LocationData currentLocation) {
  22. location(currentLocation);
  23. });
  24. }).catchError((e) {
  25. print(e);
  26. var message = e.message.toString().contains('CANCELED')
  27. ? '您取消了, 确定后将退出程序'
  28. : e.message;
  29. // Get.dialog();
  30. // Get.defaultDialog(
  31. // title: '提示',
  32. // middleText: message,
  33. // radius: 8,
  34. // textConfirm: '确定',
  35. // onConfirm: () => exit(1),
  36. // );
  37. });
  38. // // 尝试获取一次人员信息
  39. // getCurrent().then((person) {
  40. // user(person);
  41. // }).catchError((e) {
  42. // print(e);
  43. // });
  44. }
  45. }