You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
921 B

2 weeks ago
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
class MyController extends GetxController {
// 响应式变量,用于存储用户信息
var userName = '张兰雪'.obs;
var userPhone = '138****8547'.obs;
@override
void onInit() {
super.onInit();
_loadUserInfo();
}
// 从本地存储或API加载用户信息
void _loadUserInfo() {
// 假设你从 GetStorage 中读取用户信息
final box = GetStorage();
final storedUserName = box.read('userName');
final storedUserPhone = box.read('userPhone');
if (storedUserName != null) {
userName.value = storedUserName;
}
if (storedUserPhone != null) {
// 可以在此处对手机号进行格式化处理
userPhone.value = storedUserPhone;
}
// 或者,你也可以在这里调用 API 来获取用户信息
}
// 未来可以添加更新用户信息的逻辑
}