import 'dart:io'; import 'package:farmer_client/models/entities/person.dart'; import 'package:get/get.dart'; import 'package:location/location.dart'; import '../services/user.dart'; import '../utils/location.dart'; class AppController extends GetxController { // 有了这句, 可以直接 AppController.t 调用 static AppController t = Get.find(); final user = Rx(Person()); final location = Rxn(); final testInt = 1.obs; @override void onInit() { super.onInit(); // 尝试获取 location requireLocation().then((loc) async { var _data = await loc.getLocation(); location(_data); // 监听位置变化 loc.onLocationChanged.listen((LocationData currentLocation) { location(currentLocation); }); }).catchError((e) { print(e); Get.defaultDialog( title: e.message, onConfirm: () => exit(1), ); }); // 尝试获取一次人员信息 getCurrent().then((person) { user(person); }).catchError((e) { print(e); }); } }