1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
-
- 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>(Person());
- final location = Rxn<LocationData>();
- 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);
-
- var message = e.message.toString().contains('CANCELED')
- ? '您取消了, 确定后将退出程序'
- : e.message;
-
- // Get.dialog();
- // Get.defaultDialog(
- // title: '提示',
- // middleText: message,
- // radius: 8,
- // textConfirm: '确定',
- // onConfirm: () => exit(1),
- // );
- });
-
- // // 尝试获取一次人员信息
- // getCurrent().then((person) {
- // user(person);
- // }).catchError((e) {
- // print(e);
- // });
- }
-
- }
|