refactor: 优化日历状态管理与首页输入框,添加API客户端抽象
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'api_client.dart';
|
||||
import 'mock_api_client.dart';
|
||||
|
||||
abstract class IApiClient {
|
||||
Future<Response<T>> get<T>(String path, {Options? options});
|
||||
Future<Response<T>> post<T>(String path, {dynamic data, Options? options});
|
||||
Future<Response<T>> patch<T>(String path, {dynamic data, Options? options});
|
||||
Future<Response<T>> delete<T>(String path, {dynamic data, Options? options});
|
||||
}
|
||||
|
||||
class ApiClientWrapper implements IApiClient {
|
||||
final ApiClient _client;
|
||||
|
||||
ApiClientWrapper(this._client);
|
||||
|
||||
@override
|
||||
Future<Response<T>> get<T>(String path, {Options? options}) =>
|
||||
_client.get(path, options: options);
|
||||
|
||||
@override
|
||||
Future<Response<T>> post<T>(String path, {dynamic data, Options? options}) =>
|
||||
_client.post(path, data: data, options: options);
|
||||
|
||||
@override
|
||||
Future<Response<T>> patch<T>(String path, {dynamic data, Options? options}) =>
|
||||
_client.patch(path, data: data, options: options);
|
||||
|
||||
@override
|
||||
Future<Response<T>> delete<T>(
|
||||
String path, {
|
||||
dynamic data,
|
||||
Options? options,
|
||||
}) => _client.delete(path, data: data, options: options);
|
||||
}
|
||||
|
||||
class MockApiClientWrapper implements IApiClient {
|
||||
final MockApiClient _client;
|
||||
|
||||
MockApiClientWrapper(this._client);
|
||||
|
||||
@override
|
||||
Future<Response<T>> get<T>(String path, {Options? options}) =>
|
||||
_client.get(path, options: options);
|
||||
|
||||
@override
|
||||
Future<Response<T>> post<T>(String path, {dynamic data, Options? options}) =>
|
||||
_client.post(path, data: data, options: options);
|
||||
|
||||
@override
|
||||
Future<Response<T>> patch<T>(String path, {dynamic data, Options? options}) =>
|
||||
_client.patch(path, data: data, options: options);
|
||||
|
||||
@override
|
||||
Future<Response<T>> delete<T>(
|
||||
String path, {
|
||||
dynamic data,
|
||||
Options? options,
|
||||
}) => _client.delete(path, data: data, options: options);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class MockApiClient {
|
||||
final Map<String, _MockHandler> _handlers = {};
|
||||
|
||||
void registerHandler(String path, String method, _MockHandler handler) {
|
||||
final key = '$path:$method';
|
||||
_handlers[key] = handler;
|
||||
}
|
||||
|
||||
void clearMocks() {
|
||||
_handlers.clear();
|
||||
}
|
||||
|
||||
Future<Response<T>> get<T>(String path, {Options? options}) async {
|
||||
return _handleRequest('GET', path, options: options);
|
||||
}
|
||||
|
||||
Future<Response<T>> post<T>(
|
||||
String path, {
|
||||
dynamic data,
|
||||
Options? options,
|
||||
}) async {
|
||||
return _handleRequest('POST', path, data: data, options: options);
|
||||
}
|
||||
|
||||
Future<Response<T>> patch<T>(
|
||||
String path, {
|
||||
dynamic data,
|
||||
Options? options,
|
||||
}) async {
|
||||
return _handleRequest('PATCH', path, data: data, options: options);
|
||||
}
|
||||
|
||||
Future<Response<T>> delete<T>(
|
||||
String path, {
|
||||
dynamic data,
|
||||
Options? options,
|
||||
}) async {
|
||||
return _handleRequest('DELETE', path, data: data, options: options);
|
||||
}
|
||||
|
||||
Future<Response<T>> _handleRequest<T>(
|
||||
String method,
|
||||
String path, {
|
||||
dynamic data,
|
||||
Options? options,
|
||||
}) async {
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
|
||||
final key = '$path:$method';
|
||||
final handler = _handlers[key];
|
||||
|
||||
if (handler != null) {
|
||||
final response = handler(data);
|
||||
if (response is Response) {
|
||||
return response as Response<T>;
|
||||
}
|
||||
return Response<T>(
|
||||
data: response as T?,
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: path),
|
||||
);
|
||||
}
|
||||
|
||||
return Response<T>(
|
||||
data: null,
|
||||
statusCode: 404,
|
||||
requestOptions: RequestOptions(path: path),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
typedef _MockHandler = dynamic Function(dynamic data);
|
||||
|
||||
class MockApiClientHolder {
|
||||
static MockApiClient? _instance;
|
||||
|
||||
static MockApiClient get instance {
|
||||
_instance ??= MockApiClient();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
static void reset() {
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,12 @@ class Env {
|
||||
}
|
||||
return 'http://localhost:5775';
|
||||
}
|
||||
|
||||
static bool get isMockApi {
|
||||
final fromDefine = const String.fromEnvironment('MOCK_API');
|
||||
if (fromDefine.isNotEmpty) {
|
||||
return fromDefine == 'true';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../../features/auth/data/auth_api.dart';
|
||||
import '../../features/auth/data/auth_repository.dart';
|
||||
import '../../features/auth/data/auth_repository_impl.dart';
|
||||
import '../../features/auth/presentation/bloc/auth_bloc.dart';
|
||||
import '../../features/calendar/ui/calendar_state_manager.dart';
|
||||
|
||||
final sl = GetIt.instance;
|
||||
|
||||
@@ -46,4 +47,6 @@ Future<void> configureDependencies() async {
|
||||
});
|
||||
|
||||
sl.registerSingleton<AuthBloc>(AuthBloc(authRepository));
|
||||
|
||||
sl.registerSingleton<CalendarStateManager>(CalendarStateManager());
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../../features/contacts/ui/screens/add_contact_screen.dart';
|
||||
import '../../features/calendar/ui/screens/calendar_dayweek_screen.dart';
|
||||
import '../../features/calendar/ui/screens/calendar_month_screen.dart';
|
||||
import '../../features/calendar/ui/screens/calendar_event_detail_screen.dart';
|
||||
import '../../features/calendar/ui/calendar_time_utils.dart';
|
||||
import '../../features/todo/ui/screens/todo_quadrants_screen.dart';
|
||||
import '../../features/todo/ui/screens/todo_detail_screen.dart';
|
||||
import '../../features/settings/ui/screens/settings_screen.dart';
|
||||
@@ -44,6 +45,7 @@ GoRouter createAppRouter(AuthBloc authBloc) {
|
||||
final authState = authBloc.state;
|
||||
final isAuthenticated = authState is AuthAuthenticated;
|
||||
final isAuthRoute =
|
||||
state.matchedLocation == '/' ||
|
||||
state.matchedLocation.startsWith('/login') ||
|
||||
state.matchedLocation.startsWith('/register');
|
||||
final isProtected = _protectedRoutes.any(
|
||||
@@ -91,11 +93,21 @@ GoRouter createAppRouter(AuthBloc authBloc) {
|
||||
),
|
||||
GoRoute(
|
||||
path: '/calendar/dayweek',
|
||||
builder: (context, state) => const CalendarDayWeekScreen(),
|
||||
builder: (context, state) {
|
||||
final fromHome = state.uri.queryParameters['from'] == 'home';
|
||||
final initialDate = parseYmd(state.uri.queryParameters['date']);
|
||||
return CalendarDayWeekScreen(
|
||||
initialDate: initialDate,
|
||||
resetToToday: fromHome,
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/calendar/month',
|
||||
builder: (context, state) => const CalendarMonthScreen(),
|
||||
builder: (context, state) {
|
||||
final fromHome = state.uri.queryParameters['from'] == 'home';
|
||||
return CalendarMonthScreen(resetToToday: fromHome);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/calendar/events/:id',
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
DateTime weekStartFor(DateTime date) {
|
||||
return date.subtract(Duration(days: date.weekday % 7));
|
||||
}
|
||||
|
||||
bool isSameDay(DateTime a, DateTime b) {
|
||||
return a.year == b.year && a.month == b.month && a.day == b.day;
|
||||
}
|
||||
|
||||
bool shouldShowCurrentMarker(DateTime selectedDate, DateTime now) {
|
||||
return isSameDay(selectedDate, now);
|
||||
}
|
||||
|
||||
String formatHm(DateTime dateTime) {
|
||||
final hour = dateTime.hour.toString().padLeft(2, '0');
|
||||
final minute = dateTime.minute.toString().padLeft(2, '0');
|
||||
return '$hour:$minute';
|
||||
}
|
||||
|
||||
String formatHour(int hour) {
|
||||
if (hour == 24) {
|
||||
return '00:00';
|
||||
}
|
||||
return '${hour.toString().padLeft(2, '0')}:00';
|
||||
}
|
||||
|
||||
DateTime? parseYmd(String? ymd) {
|
||||
if (ymd == null) {
|
||||
return null;
|
||||
}
|
||||
final matched = RegExp(r'^(\d{4})-(\d{2})-(\d{2})$').firstMatch(ymd);
|
||||
if (matched == null) {
|
||||
return null;
|
||||
}
|
||||
final year = int.parse(matched.group(1)!);
|
||||
final month = int.parse(matched.group(2)!);
|
||||
final day = int.parse(matched.group(3)!);
|
||||
final parsed = DateTime(year, month, day);
|
||||
if (parsed.year != year || parsed.month != month || parsed.day != day) {
|
||||
return null;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
String formatYmd(DateTime dateTime) {
|
||||
final year = dateTime.year.toString().padLeft(4, '0');
|
||||
final month = dateTime.month.toString().padLeft(2, '0');
|
||||
final day = dateTime.day.toString().padLeft(2, '0');
|
||||
return '$year-$month-$day';
|
||||
}
|
||||
|
||||
List<DateTime> monthDatesFor(DateTime date) {
|
||||
final monthStart = DateTime(date.year, date.month, 1);
|
||||
final monthEnd = DateTime(date.year, date.month + 1, 0);
|
||||
return List.generate(
|
||||
monthEnd.day,
|
||||
(index) => DateTime(monthStart.year, monthStart.month, index + 1),
|
||||
);
|
||||
}
|
||||
@@ -1,34 +1,66 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../calendar_state_manager.dart';
|
||||
import '../calendar_time_utils.dart';
|
||||
import '../widgets/bottom_dock.dart';
|
||||
|
||||
class CalendarDayWeekScreen extends StatefulWidget {
|
||||
const CalendarDayWeekScreen({super.key});
|
||||
final DateTime? initialDate;
|
||||
final bool resetToToday;
|
||||
|
||||
const CalendarDayWeekScreen({
|
||||
super.key,
|
||||
this.initialDate,
|
||||
this.resetToToday = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CalendarDayWeekScreen> createState() => _CalendarDayWeekScreenState();
|
||||
}
|
||||
|
||||
class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
DateTime _selectedDate = DateTime(2026, 2, 9);
|
||||
late DateTime _weekStart;
|
||||
static const double _dayItemWidth = 44;
|
||||
static const double _dayItemGap = 12;
|
||||
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _selectedDate;
|
||||
late List<DateTime> _monthDates;
|
||||
final ScrollController _dayStripController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_weekStart = _getWeekStart(_selectedDate);
|
||||
_calendarManager = sl<CalendarStateManager>();
|
||||
|
||||
if (widget.resetToToday) {
|
||||
_calendarManager.resetToToday();
|
||||
}
|
||||
|
||||
_selectedDate = _calendarManager.selectedDate;
|
||||
_updateMonthDates();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_scrollToSelectedDate();
|
||||
});
|
||||
}
|
||||
|
||||
DateTime _getWeekStart(DateTime date) {
|
||||
return date.subtract(Duration(days: date.weekday % 7));
|
||||
void _updateMonthDates() {
|
||||
_monthDates = monthDatesFor(_selectedDate);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_dayStripController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8FAFC),
|
||||
backgroundColor: AppColors.todoBg,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -37,8 +69,8 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
left: AppSpacing.lg,
|
||||
right: AppSpacing.lg,
|
||||
top: 2,
|
||||
bottom: 104,
|
||||
),
|
||||
@@ -67,14 +99,14 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
onTap: () => context.go('/calendar/month'),
|
||||
child: Container(
|
||||
height: 36,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8FAFF),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(color: const Color(0xFFDEE7F6)),
|
||||
color: AppColors.messageBtnWrap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.messageBtnBorder),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -106,29 +138,70 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
Widget _buildWeekStrip() {
|
||||
return SizedBox(
|
||||
height: 86,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: List.generate(7, (index) {
|
||||
final date = _weekStart.add(Duration(days: index));
|
||||
final isSelected =
|
||||
date.day == _selectedDate.day &&
|
||||
date.month == _selectedDate.month &&
|
||||
date.year == _selectedDate.year;
|
||||
final isWeekend = index == 0 || index == 6;
|
||||
child: ListView.separated(
|
||||
controller: _dayStripController,
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: _monthDates.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(width: _dayItemGap),
|
||||
itemBuilder: (context, index) {
|
||||
final date = _monthDates[index];
|
||||
final isSelected = isSameDay(date, _selectedDate);
|
||||
final isWeekend = date.weekday % 7 == 0 || date.weekday % 7 == 6;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedDate = date;
|
||||
});
|
||||
_calendarManager.setSelectedDate(date);
|
||||
_updateMonthDates();
|
||||
_scrollToSelectedDate(animate: true);
|
||||
},
|
||||
child: _buildDayItem(date, isSelected, isWeekend),
|
||||
child: SizedBox(
|
||||
width: _dayItemWidth,
|
||||
child: _buildDayItem(date, isSelected, isWeekend),
|
||||
),
|
||||
);
|
||||
}),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _scrollToSelectedDate({bool animate = false}) {
|
||||
if (!_dayStripController.hasClients) {
|
||||
return;
|
||||
}
|
||||
final index = _monthDates.indexWhere(
|
||||
(date) => isSameDay(date, _selectedDate),
|
||||
);
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final targetCenter =
|
||||
index * (_dayItemWidth + _dayItemGap) + (_dayItemWidth / 2);
|
||||
final viewport = _dayStripController.position.viewportDimension;
|
||||
var offset = targetCenter - (viewport / 2);
|
||||
final max = _dayStripController.position.maxScrollExtent;
|
||||
if (offset < 0) {
|
||||
offset = 0;
|
||||
}
|
||||
if (offset > max) {
|
||||
offset = max;
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
_dayStripController.animateTo(
|
||||
offset,
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
return;
|
||||
}
|
||||
_dayStripController.jumpTo(offset);
|
||||
}
|
||||
|
||||
Widget _buildDayItem(DateTime date, bool isSelected, bool isWeekend) {
|
||||
final dayNames = ['日', '一', '二', '三', '四', '五', '六'];
|
||||
|
||||
@@ -146,7 +219,7 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
Text(
|
||||
'${date.day}',
|
||||
style: TextStyle(
|
||||
fontSize: isSelected ? 17 : (isWeekend ? 17 : 17),
|
||||
fontSize: 17,
|
||||
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w600,
|
||||
color: isSelected
|
||||
? AppColors.blue600
|
||||
@@ -158,49 +231,23 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
}
|
||||
|
||||
Widget _buildTimelineBoard() {
|
||||
return Column(
|
||||
children: [
|
||||
_buildTimelineRow('07:00', false),
|
||||
_buildTimelineRow('08:00', false),
|
||||
_buildTimelineRow(
|
||||
'09:00',
|
||||
true,
|
||||
eventText: '购票提醒',
|
||||
eventColor: AppColors.slate500,
|
||||
),
|
||||
_buildTimelineRow('10:00', false),
|
||||
_buildTimelineRow('11:00', false),
|
||||
_buildTimelineRow('12:00', false),
|
||||
_buildTimelineRow('13:00', false),
|
||||
_buildTimelineRow('14:00', false),
|
||||
_buildTimelineRow('15:00', false),
|
||||
_buildTimelineRow('15:28', false, isCurrentTime: true),
|
||||
_buildTimelineRow(
|
||||
'16:00',
|
||||
true,
|
||||
eventText: '购票提醒',
|
||||
eventColor: const Color(0xFF6B21A8),
|
||||
eventBg: const Color(0xFFE9D5FF),
|
||||
eventBorder: const Color(0xFFD8B4FE),
|
||||
),
|
||||
_buildTimelineRow('17:00', false),
|
||||
_buildTimelineRow('18:00', false),
|
||||
_buildTimelineRow('19:00', false),
|
||||
_buildTimelineRow('20:00', false),
|
||||
_buildTimelineRow('21:00', false),
|
||||
_buildTimelineRow('22:00', false),
|
||||
_buildTimelineRow('00:00', false, isDisabled: true),
|
||||
],
|
||||
);
|
||||
final now = DateTime.now();
|
||||
final showCurrent = shouldShowCurrentMarker(_selectedDate, now);
|
||||
final rows = <Widget>[];
|
||||
|
||||
for (var hour = 7; hour <= 22; hour++) {
|
||||
rows.add(_buildTimelineRow(formatHour(hour)));
|
||||
if (showCurrent && now.hour == hour) {
|
||||
rows.add(_buildTimelineRow(formatHm(now), isCurrentTime: true));
|
||||
}
|
||||
}
|
||||
|
||||
rows.add(_buildTimelineRow(formatHour(24), isDisabled: true));
|
||||
return Column(children: rows);
|
||||
}
|
||||
|
||||
Widget _buildTimelineRow(
|
||||
String time,
|
||||
bool hasEvent, {
|
||||
String? eventText,
|
||||
Color? eventColor,
|
||||
Color? eventBg,
|
||||
Color? eventBorder,
|
||||
String time, {
|
||||
bool isCurrentTime = false,
|
||||
bool isDisabled = false,
|
||||
}) {
|
||||
@@ -215,7 +262,7 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
width: 44,
|
||||
height: 18,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEF4444),
|
||||
color: AppColors.red500,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
child: Center(
|
||||
@@ -237,7 +284,7 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isDisabled
|
||||
? AppColors.slate300
|
||||
: const Color(0xFF9CA3AF),
|
||||
: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -247,38 +294,13 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
? Container(
|
||||
height: 2,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEF4444),
|
||||
color: AppColors.red500,
|
||||
borderRadius: BorderRadius.circular(99),
|
||||
),
|
||||
)
|
||||
: hasEvent
|
||||
? Container(
|
||||
height: 22,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: eventBg ?? const Color(0xFFE5E7EB),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: eventBorder ?? const Color(0xFFD1D5DB),
|
||||
),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
eventText ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: eventColor ?? const Color(0xFF6B7280),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
height: 1,
|
||||
color: isDisabled
|
||||
? const Color(0xFFECEFF4)
|
||||
: const Color(0xFFE5E7EB),
|
||||
color: isDisabled ? AppColors.blue50 : AppColors.border,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -289,9 +311,15 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
Widget _buildBottomDock() {
|
||||
return BottomDock(
|
||||
activeTab: DockTab.calendar,
|
||||
onTodoTap: () => context.push('/todo'),
|
||||
onCalendarTap: () {},
|
||||
onHomeTap: () => Navigator.of(context).pop(),
|
||||
onTodoTap: () {
|
||||
_calendarManager.setViewType(CalendarViewType.day);
|
||||
context.push('/todo');
|
||||
},
|
||||
onCalendarTap: () {
|
||||
_calendarManager.setViewType(CalendarViewType.day);
|
||||
context.go('/calendar/month');
|
||||
},
|
||||
onHomeTap: () => context.go('/home'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,24 +2,44 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../calendar_state_manager.dart';
|
||||
import '../calendar_time_utils.dart';
|
||||
import '../widgets/bottom_dock.dart';
|
||||
|
||||
class CalendarMonthScreen extends StatefulWidget {
|
||||
const CalendarMonthScreen({super.key});
|
||||
final bool resetToToday;
|
||||
|
||||
const CalendarMonthScreen({super.key, this.resetToToday = false});
|
||||
|
||||
@override
|
||||
State<CalendarMonthScreen> createState() => _CalendarMonthScreenState();
|
||||
}
|
||||
|
||||
class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
DateTime _currentMonth = DateTime(2026, 2, 1);
|
||||
DateTime? _selectedDate;
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _currentMonth;
|
||||
late DateTime _selectedDate;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_calendarManager = sl<CalendarStateManager>();
|
||||
|
||||
if (widget.resetToToday) {
|
||||
_calendarManager.resetToToday();
|
||||
}
|
||||
|
||||
final savedDate = _calendarManager.selectedDate;
|
||||
_selectedDate = savedDate;
|
||||
_currentMonth = DateTime(savedDate.year, savedDate.month, 1);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8FAFC),
|
||||
backgroundColor: AppColors.todoBg,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -84,7 +104,7 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
return Column(
|
||||
children: [
|
||||
_buildWeekdayHeader(),
|
||||
Container(height: 1, color: const Color(0xFFE5E7EB)),
|
||||
Container(height: 1, color: AppColors.border),
|
||||
..._buildWeeks(),
|
||||
],
|
||||
);
|
||||
@@ -108,7 +128,7 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF9CA3AF),
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -140,7 +160,7 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
for (var weekStart = 0; weekStart < totalCells; weekStart += 7) {
|
||||
weeks.add(_buildWeekRow(weekStart, startWeekday, daysInMonth));
|
||||
if (weekStart + 7 < totalCells) {
|
||||
weeks.add(Container(height: 1, color: const Color(0xFFE5E7EB)));
|
||||
weeks.add(Container(height: 1, color: AppColors.border));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,24 +185,23 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
_currentMonth.month,
|
||||
dayIndex,
|
||||
);
|
||||
final isSelected =
|
||||
_selectedDate != null &&
|
||||
_selectedDate!.day == dayIndex &&
|
||||
_selectedDate!.month == _currentMonth.month;
|
||||
final isSelected = isSameDay(_selectedDate, date);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedDate = date;
|
||||
});
|
||||
_calendarManager.setSelectedDate(date);
|
||||
_calendarManager.setViewType(CalendarViewType.month);
|
||||
final ymd = formatYmd(date);
|
||||
context.push('/calendar/dayweek?date=$ymd');
|
||||
},
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? const Color(0xFFDBEAFE)
|
||||
: Colors.transparent,
|
||||
color: isSelected ? AppColors.blue100 : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: Center(
|
||||
@@ -217,64 +236,15 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: List.generate(7, (index) {
|
||||
final dayIndex = weekStart + index - startWeekday + 1;
|
||||
if (dayIndex == 10) {
|
||||
return _buildEventDot();
|
||||
if (dayIndex < 1 || dayIndex > daysInMonth) {
|
||||
return const SizedBox(width: 38, height: 1);
|
||||
}
|
||||
return const SizedBox(width: 38, height: 1);
|
||||
return const SizedBox(width: 38, height: 20);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventDot() {
|
||||
return SizedBox(
|
||||
width: 76,
|
||||
height: 100,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
height: 20,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE5E7EB),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'购票提醒',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF6B7280),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
height: 20,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE9D5FF),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'购票提醒',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF6B21A8),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showMonthPicker() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
@@ -351,9 +321,12 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
Widget _buildBottomDock() {
|
||||
return BottomDock(
|
||||
activeTab: DockTab.calendar,
|
||||
onTodoTap: () => context.push('/todo'),
|
||||
onTodoTap: () {
|
||||
_calendarManager.setViewType(CalendarViewType.month);
|
||||
context.push('/todo');
|
||||
},
|
||||
onCalendarTap: () {},
|
||||
onHomeTap: () => Navigator.of(context).pop(),
|
||||
onHomeTap: () => context.go('/home'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
|
||||
enum DockTab { todo, calendar }
|
||||
|
||||
@@ -20,8 +21,13 @@ class BottomDock extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 61,
|
||||
padding: const EdgeInsets.only(left: 20, right: 20, top: 12, bottom: 18),
|
||||
height: 72,
|
||||
padding: const EdgeInsets.only(
|
||||
left: AppSpacing.xl,
|
||||
right: AppSpacing.xl,
|
||||
top: AppSpacing.md,
|
||||
bottom: AppSpacing.lg,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [_buildToggle(), _buildHomeBtn()],
|
||||
@@ -33,9 +39,9 @@ class BottomDock extends StatelessWidget {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFDFEFF),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(color: const Color(0xFFDCE6F4)),
|
||||
color: AppColors.todoToggleBg,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xxl),
|
||||
border: Border.all(color: AppColors.todoToggleBorder),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -67,16 +73,18 @@ class BottomDock extends StatelessWidget {
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? const Color(0xFFD6E6FF) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
color: isActive ? AppColors.todoToggleActiveBg : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(
|
||||
color: isActive ? const Color(0xFFBFD6FB) : Colors.transparent,
|
||||
color: isActive
|
||||
? AppColors.todoToggleActiveBorder
|
||||
: Colors.transparent,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: isActive ? const Color(0xFF1D4ED8) : const Color(0xFF334155),
|
||||
color: isActive ? AppColors.blue600 : AppColors.slate700,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -89,11 +97,15 @@ class BottomDock extends StatelessWidget {
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE6EEFB),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(color: const Color(0xFFC9D8EE)),
|
||||
color: AppColors.todoHomeBtnBg,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.todoHomeBtnBorder),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.home,
|
||||
size: 20,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
child: const Icon(LucideIcons.home, size: 20, color: Color(0xFF1E3A8A)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,35 @@ import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import 'home_sheet.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
final TextEditingController _messageController = TextEditingController();
|
||||
|
||||
bool get _hasMessage => _messageController.text.trim().isNotEmpty;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_messageController.addListener(_onMessageChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_messageController.removeListener(_onMessageChanged);
|
||||
_messageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onMessageChanged() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -47,7 +73,7 @@ class HomeScreen extends StatelessWidget {
|
||||
size: 24,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
onPressed: () => context.push('/calendar/dayweek'),
|
||||
onPressed: () => context.push('/calendar/dayweek?from=home'),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
IconButton(
|
||||
@@ -153,10 +179,10 @@ class HomeScreen extends StatelessWidget {
|
||||
|
||||
Widget _buildInputContainer(BuildContext context) {
|
||||
return Container(
|
||||
height: 80,
|
||||
padding: const EdgeInsets.all(16),
|
||||
color: const Color(0xFFF8FAFC),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => _showBottomSheet(context),
|
||||
@@ -166,7 +192,7 @@ class HomeScreen extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: const Color(0xFFE2E8F0)),
|
||||
border: Border.all(color: AppColors.slate300),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.plus,
|
||||
@@ -178,28 +204,40 @@ class HomeScreen extends StatelessWidget {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 48,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
constraints: const BoxConstraints(minHeight: 48),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(color: AppColors.slate300),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Expanded(
|
||||
Expanded(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
controller: _messageController,
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '输入消息...',
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
focusedErrorBorder: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
filled: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
LucideIcons.mic,
|
||||
size: 20,
|
||||
color: AppColors.slate500,
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
_hasMessage ? LucideIcons.send : LucideIcons.mic,
|
||||
size: 24,
|
||||
color: _hasMessage ? AppColors.blue600 : AppColors.slate500,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../calendar/ui/calendar_state_manager.dart';
|
||||
|
||||
class TodoQuadrantsScreen extends StatelessWidget {
|
||||
const TodoQuadrantsScreen({super.key});
|
||||
@@ -216,7 +218,18 @@ class TodoQuadrantsScreen extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
GestureDetector(
|
||||
onTap: () => context.push('/calendar/dayweek'),
|
||||
onTap: () {
|
||||
final manager = sl<CalendarStateManager>();
|
||||
final viewType = manager.viewType;
|
||||
final date = manager.selectedDate;
|
||||
final dateStr =
|
||||
'${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
if (viewType == CalendarViewType.month) {
|
||||
context.push('/calendar/month');
|
||||
} else {
|
||||
context.push('/calendar/dayweek?date=$dateStr');
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
|
||||
+12
-1
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'core/config/env.dart';
|
||||
import 'core/di/injection.dart';
|
||||
import 'core/router/app_router.dart';
|
||||
import 'core/theme/app_theme.dart';
|
||||
import 'features/auth/data/models/auth_response.dart';
|
||||
import 'features/auth/presentation/bloc/auth_bloc.dart';
|
||||
import 'features/auth/presentation/bloc/auth_event.dart';
|
||||
|
||||
@@ -11,7 +13,16 @@ void main() async {
|
||||
await configureDependencies();
|
||||
|
||||
final authBloc = sl<AuthBloc>();
|
||||
authBloc.add(AuthStarted());
|
||||
|
||||
if (Env.isMockApi) {
|
||||
authBloc.add(
|
||||
AuthLoggedIn(
|
||||
user: AuthUser(id: 'user_001', email: 'test@example.com'),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
authBloc.add(AuthStarted());
|
||||
}
|
||||
|
||||
runApp(LinksyApp(authBloc: authBloc));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user