refactor(apps): 主题系统迁移至 ColorScheme + 扩展架构并支持 Dark Mode
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum CalendarViewType { day, month }
|
||||
|
||||
class CalendarState {
|
||||
final CalendarViewType viewType;
|
||||
final DateTime selectedDate;
|
||||
|
||||
CalendarState({required this.viewType, required this.selectedDate});
|
||||
|
||||
CalendarState copyWith({CalendarViewType? viewType, DateTime? selectedDate}) {
|
||||
return CalendarState(
|
||||
viewType: viewType ?? this.viewType,
|
||||
selectedDate: selectedDate ?? this.selectedDate,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CalendarStateManager extends ChangeNotifier {
|
||||
CalendarState _state;
|
||||
|
||||
CalendarStateManager()
|
||||
: _state = CalendarState(
|
||||
viewType: CalendarViewType.month,
|
||||
selectedDate: DateTime.now(),
|
||||
);
|
||||
|
||||
CalendarState get state => _state;
|
||||
|
||||
CalendarViewType get viewType => _state.viewType;
|
||||
DateTime get selectedDate => _state.selectedDate;
|
||||
|
||||
void setViewType(CalendarViewType type) {
|
||||
_state = _state.copyWith(viewType: type);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setSelectedDate(DateTime date) {
|
||||
_state = _state.copyWith(selectedDate: date);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void resetToToday() {
|
||||
final now = DateTime.now();
|
||||
_state = CalendarState(
|
||||
viewType: CalendarViewType.month,
|
||||
selectedDate: DateTime(now.year, now.month, now.day),
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user