home_controller.dart
794 Bytes
import 'package:doublefeel_flutter/core/services/user_state_service.dart';
import 'package:get/get.dart';
class HomeController extends GetxController {
final UserStateService userStateService = Get.find<UserStateService>();
/// 当前选中的底部 tab 索引
final selectedIndex = 0.obs;
/// 当前选中的日期(Today tab 使用)
final selectedDate = _dateOnly(DateTime.now()).obs;
void changeTab(int index) {
selectedIndex.value = index;
}
void changeDate(DateTime date) {
final normalizedDate = _dateOnly(date);
final currentDate = selectedDate.value;
if (currentDate == normalizedDate) return;
selectedDate.value = normalizedDate;
}
static DateTime _dateOnly(DateTime date) {
return DateTime(date.year, date.month, date.day);
}
}