refactor(apps): 主题系统迁移至 ColorScheme + 扩展架构并支持 Dark Mode
This commit is contained in:
@@ -3,6 +3,8 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../app/di/injection.dart';
|
||||
import '../../../../data/repositories/calendar_event_repository.dart';
|
||||
import '../../../../data/repositories/models/calendar_event.dart';
|
||||
import '../../../../core/l10n/l10n.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
@@ -13,8 +15,6 @@ import '../../../../shared/widgets/error_retry_surface.dart';
|
||||
import '../../../../shared/widgets/full_screen_loading.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../../calendar/data/calendar_api.dart';
|
||||
import '../../../calendar/data/models/schedule_item_model.dart';
|
||||
import '../../data/todo_api.dart';
|
||||
|
||||
class TodoEditScreen extends StatefulWidget {
|
||||
@@ -32,7 +32,8 @@ class TodoEditScreen extends StatefulWidget {
|
||||
|
||||
class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
final TodoApi _todoApi = sl<TodoApi>();
|
||||
final CalendarApi _calendarApi = sl<CalendarApi>();
|
||||
final CalendarEventRepository _calendarRepository =
|
||||
sl<CalendarEventRepository>();
|
||||
|
||||
final TextEditingController _titleController = TextEditingController();
|
||||
final TextEditingController _descriptionController = TextEditingController();
|
||||
@@ -46,6 +47,8 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
final Set<String> _selectedScheduleItemIds = <String>{};
|
||||
List<_ScheduleItemSimple> _scheduleItems = const <_ScheduleItemSimple>[];
|
||||
|
||||
ColorScheme get _colorScheme => Theme.of(context).colorScheme;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -69,7 +72,7 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
final now = DateTime.now();
|
||||
final start = now.subtract(const Duration(days: 30));
|
||||
final end = now.add(const Duration(days: 90));
|
||||
final scheduleItems = await _calendarApi.listByRange(
|
||||
final scheduleItems = await _calendarRepository.listByRange(
|
||||
startAt: start,
|
||||
endAt: end,
|
||||
);
|
||||
@@ -91,7 +94,7 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
..clear()
|
||||
..addAll(todo?.scheduleItems.map((item) => item.id) ?? const []);
|
||||
_scheduleItems = scheduleItems
|
||||
.where((item) => item.status == ScheduleStatus.active)
|
||||
.where((item) => item.status == CalendarEventStatus.active)
|
||||
.map(
|
||||
(item) => _ScheduleItemSimple(
|
||||
id: item.id,
|
||||
@@ -118,18 +121,21 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.todoBg,
|
||||
backgroundColor: _colorScheme.surface,
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: SafeArea(
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [AppColors.homeBackgroundTop, AppColors.todoBg],
|
||||
colors: [
|
||||
_colorScheme.surfaceContainerLow,
|
||||
_colorScheme.surface,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
@@ -184,15 +190,21 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
}
|
||||
|
||||
Widget _buildHeaderCard() {
|
||||
final headerDesc = widget.isCreateMode
|
||||
? context.l10n.todoInfoDescCreate
|
||||
: _todo?.status == 'done'
|
||||
? context.l10n.todoInfoDescDone
|
||||
: context.l10n.todoInfoDescDefault;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
color: _colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderTertiary),
|
||||
border: Border.all(color: _colorScheme.outlineVariant),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.slate200.withValues(alpha: 0.34),
|
||||
color: _colorScheme.shadow.withValues(alpha: 0.18),
|
||||
blurRadius: AppRadius.lg,
|
||||
offset: const Offset(0, AppSpacing.xs),
|
||||
),
|
||||
@@ -206,17 +218,16 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
color: _colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
widget.isCreateMode
|
||||
? context.l10n.todoInfoDescCreate
|
||||
: _todo?.status == 'done'
|
||||
? context.l10n.todoInfoDescDone
|
||||
: context.l10n.todoInfoDescDefault,
|
||||
style: const TextStyle(fontSize: 13, color: AppColors.slate500),
|
||||
headerDesc,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: _colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -227,9 +238,9 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
color: _colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
border: Border.all(color: _colorScheme.outlineVariant),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -252,7 +263,7 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
color: _colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
@@ -263,22 +274,22 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
_PriorityPill(
|
||||
label: context.l10n.todoQuadrantImportantUrgent,
|
||||
selected: _priority == 1,
|
||||
borderColor: AppColors.g1Border,
|
||||
activeColor: AppColors.g1Text,
|
||||
borderColor: _colorScheme.error,
|
||||
activeColor: _colorScheme.error,
|
||||
onTap: () => setState(() => _priority = 1),
|
||||
),
|
||||
_PriorityPill(
|
||||
label: context.l10n.todoQuadrantUrgentNotImportant,
|
||||
selected: _priority == 3,
|
||||
borderColor: AppColors.g2Border,
|
||||
activeColor: AppColors.g2Text,
|
||||
borderColor: _colorScheme.primary,
|
||||
activeColor: _colorScheme.primary,
|
||||
onTap: () => setState(() => _priority = 3),
|
||||
),
|
||||
_PriorityPill(
|
||||
label: context.l10n.todoQuadrantImportantNotUrgent,
|
||||
selected: _priority == 2,
|
||||
borderColor: AppColors.g3Border,
|
||||
activeColor: AppColors.g3Text,
|
||||
borderColor: _colorScheme.tertiary,
|
||||
activeColor: _colorScheme.tertiary,
|
||||
onTap: () => setState(() => _priority = 2),
|
||||
),
|
||||
],
|
||||
@@ -292,9 +303,9 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
color: _colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
border: Border.all(color: _colorScheme.outlineVariant),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -307,16 +318,16 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
color: _colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
context.l10n.todoItemCount(_selectedScheduleItemIds.length),
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate500,
|
||||
color: _colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -328,7 +339,7 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
child: Center(
|
||||
child: Text(
|
||||
context.l10n.todoNoSelectableCalendarEvents,
|
||||
style: const TextStyle(color: AppColors.slate500),
|
||||
style: TextStyle(color: _colorScheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -375,8 +386,8 @@ class _TodoEditScreenState extends State<TodoEditScreen> {
|
||||
AppSpacing.lg,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white.withValues(alpha: 0.9),
|
||||
border: const Border(top: BorderSide(color: AppColors.borderSecondary)),
|
||||
color: _colorScheme.surface.withValues(alpha: 0.9),
|
||||
border: Border(top: BorderSide(color: _colorScheme.outlineVariant)),
|
||||
),
|
||||
child: AppButton(
|
||||
text: _saving
|
||||
@@ -479,6 +490,8 @@ class _PriorityPill extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return AppPressable(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
@@ -492,10 +505,10 @@ class _PriorityPill extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: selected
|
||||
? borderColor.withValues(alpha: 0.28)
|
||||
: AppColors.white,
|
||||
: colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
border: Border.all(
|
||||
color: selected ? borderColor : AppColors.slate300,
|
||||
color: selected ? borderColor : colorScheme.outlineVariant,
|
||||
width: selected ? 1.5 : 1,
|
||||
),
|
||||
),
|
||||
@@ -504,7 +517,7 @@ class _PriorityPill extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
|
||||
color: selected ? activeColor : AppColors.slate600,
|
||||
color: selected ? activeColor : colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -527,6 +540,8 @@ class _ScheduleSelectableTile extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return AppPressable(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
@@ -535,10 +550,10 @@ class _ScheduleSelectableTile extends StatelessWidget {
|
||||
curve: Curves.easeOut,
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? AppColors.surfaceInfoLight : AppColors.white,
|
||||
color: selected ? colorScheme.primaryContainer : colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
border: Border.all(
|
||||
color: selected ? AppColors.borderQuaternary : AppColors.border,
|
||||
color: selected ? colorScheme.primary : colorScheme.outlineVariant,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
@@ -552,18 +567,18 @@ class _ScheduleSelectableTile extends StatelessWidget {
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate800,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.slate500,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -575,14 +590,16 @@ class _ScheduleSelectableTile extends StatelessWidget {
|
||||
width: AppSpacing.lg,
|
||||
height: AppSpacing.lg,
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? AppColors.blue600 : AppColors.white,
|
||||
color: selected ? colorScheme.primary : colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
border: Border.all(
|
||||
color: selected ? AppColors.blue600 : AppColors.slate300,
|
||||
color: selected
|
||||
? colorScheme.primary
|
||||
: colorScheme.outlineVariant,
|
||||
),
|
||||
),
|
||||
child: selected
|
||||
? const Icon(Icons.check, size: 12, color: AppColors.white)
|
||||
? Icon(Icons.check, size: 12, color: colorScheme.onPrimary)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user