feat: 增强日历功能并集成 AgentScope 代理服务
This commit is contained in:
@@ -11,6 +11,7 @@ android {
|
||||
ndkVersion = flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
isCoreLibraryDesugaringEnabled = true
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
@@ -42,3 +43,7 @@ android {
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
|
||||
dependencies {
|
||||
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../api/i_api_client.dart';
|
||||
import '../api/mock_api_client.dart';
|
||||
import '../storage/token_storage.dart';
|
||||
import '../config/env.dart';
|
||||
import '../notifications/local_notification_service.dart';
|
||||
import '../../features/auth/data/auth_api.dart';
|
||||
import '../../features/auth/data/auth_repository.dart';
|
||||
import '../../features/auth/data/auth_repository_impl.dart';
|
||||
@@ -56,6 +57,8 @@ Future<void> configureDependencies() async {
|
||||
);
|
||||
sl.registerSingleton<CalendarService>(calendarService);
|
||||
|
||||
sl.registerSingleton<LocalNotificationService>(LocalNotificationService());
|
||||
|
||||
final friendsApi = FriendsApi(apiClient);
|
||||
sl.registerSingleton<FriendsApi>(friendsApi);
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:timezone/data/latest.dart' as tz_data;
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
import '../../features/calendar/data/models/schedule_item_model.dart';
|
||||
|
||||
class LocalNotificationService {
|
||||
final FlutterLocalNotificationsPlugin _plugin;
|
||||
bool _initialized = false;
|
||||
|
||||
LocalNotificationService({FlutterLocalNotificationsPlugin? plugin})
|
||||
: _plugin = plugin ?? FlutterLocalNotificationsPlugin();
|
||||
|
||||
Future<void> initialize() async {
|
||||
if (_initialized) {
|
||||
return;
|
||||
}
|
||||
tz_data.initializeTimeZones();
|
||||
|
||||
const android = AndroidInitializationSettings('@mipmap/ic_launcher');
|
||||
const ios = DarwinInitializationSettings(
|
||||
requestAlertPermission: false,
|
||||
requestBadgePermission: false,
|
||||
requestSoundPermission: false,
|
||||
);
|
||||
const settings = InitializationSettings(android: android, iOS: ios);
|
||||
|
||||
await _plugin.initialize(settings);
|
||||
|
||||
await _plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>()
|
||||
?.requestNotificationsPermission();
|
||||
|
||||
await _plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
IOSFlutterLocalNotificationsPlugin
|
||||
>()
|
||||
?.requestPermissions(alert: true, badge: true, sound: true);
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
Future<void> upsertEventReminder(ScheduleItemModel event) async {
|
||||
await initialize();
|
||||
|
||||
final reminderMinutes = event.metadata?.reminderMinutes;
|
||||
if (reminderMinutes == null) {
|
||||
await cancelEventReminder(event.id);
|
||||
return;
|
||||
}
|
||||
|
||||
final fireAt = event.startAt.subtract(Duration(minutes: reminderMinutes));
|
||||
if (!fireAt.isAfter(DateTime.now())) {
|
||||
await cancelEventReminder(event.id);
|
||||
return;
|
||||
}
|
||||
|
||||
final notificationId = _notificationIdForEvent(event.id);
|
||||
final scheduledAt = tz.TZDateTime.from(fireAt, tz.local);
|
||||
|
||||
final details = NotificationDetails(
|
||||
android: AndroidNotificationDetails(
|
||||
'calendar_reminder_channel',
|
||||
'日历提醒',
|
||||
channelDescription: '日历事件提醒通知',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
enableVibration: true,
|
||||
),
|
||||
iOS: const DarwinNotificationDetails(
|
||||
presentAlert: true,
|
||||
presentSound: true,
|
||||
presentBadge: true,
|
||||
),
|
||||
);
|
||||
|
||||
await _plugin.zonedSchedule(
|
||||
notificationId,
|
||||
event.title,
|
||||
_buildReminderBody(event, reminderMinutes),
|
||||
scheduledAt,
|
||||
details,
|
||||
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> cancelEventReminder(String eventId) async {
|
||||
await initialize();
|
||||
await _plugin.cancel(_notificationIdForEvent(eventId));
|
||||
}
|
||||
|
||||
Future<void> rebuildUpcomingReminders(
|
||||
Iterable<ScheduleItemModel> events,
|
||||
) async {
|
||||
await initialize();
|
||||
for (final event in events) {
|
||||
await upsertEventReminder(event);
|
||||
}
|
||||
}
|
||||
|
||||
int _notificationIdForEvent(String eventId) {
|
||||
return eventId.hashCode & 0x7fffffff;
|
||||
}
|
||||
|
||||
String _buildReminderBody(ScheduleItemModel event, int reminderMinutes) {
|
||||
if (reminderMinutes == 0) {
|
||||
return '日程现在开始:${event.title}';
|
||||
}
|
||||
return '日程即将开始(提前$reminderMinutes分钟):${event.title}';
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,7 @@ class ScheduleMetadata {
|
||||
final String? color;
|
||||
final String? location;
|
||||
final String? notes;
|
||||
final int? reminderMinutes;
|
||||
final List<Attachment> attachments;
|
||||
final int version;
|
||||
final Map<String, dynamic> raw;
|
||||
@@ -120,6 +121,7 @@ class ScheduleMetadata {
|
||||
this.color,
|
||||
this.location,
|
||||
this.notes,
|
||||
this.reminderMinutes,
|
||||
List<Attachment>? attachments,
|
||||
this.version = 1,
|
||||
Map<String, dynamic>? raw,
|
||||
@@ -130,6 +132,7 @@ class ScheduleMetadata {
|
||||
String? color,
|
||||
String? location,
|
||||
String? notes,
|
||||
int? reminderMinutes,
|
||||
List<Attachment>? attachments,
|
||||
int? version,
|
||||
Map<String, dynamic>? raw,
|
||||
@@ -138,6 +141,7 @@ class ScheduleMetadata {
|
||||
color: color ?? this.color,
|
||||
location: location ?? this.location,
|
||||
notes: notes ?? this.notes,
|
||||
reminderMinutes: reminderMinutes ?? this.reminderMinutes,
|
||||
attachments: attachments ?? this.attachments,
|
||||
version: version ?? this.version,
|
||||
raw: raw ?? this.raw,
|
||||
@@ -156,6 +160,7 @@ class ScheduleMetadata {
|
||||
color: json['color'] as String?,
|
||||
location: json['location'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
reminderMinutes: json['reminder_minutes'] as int?,
|
||||
attachments: attachments,
|
||||
version: (json['version'] as int?) ?? 1,
|
||||
raw: Map<String, dynamic>.from(json),
|
||||
@@ -167,6 +172,7 @@ class ScheduleMetadata {
|
||||
'color': color,
|
||||
'location': location,
|
||||
'notes': notes,
|
||||
'reminder_minutes': reminderMinutes,
|
||||
'attachments': attachments.map((item) => item.toJson()).toList(),
|
||||
'version': version,
|
||||
};
|
||||
|
||||
@@ -24,11 +24,19 @@ class CalendarDayWeekScreen extends StatefulWidget {
|
||||
State<CalendarDayWeekScreen> createState() => _CalendarDayWeekScreenState();
|
||||
}
|
||||
|
||||
class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen>
|
||||
with WidgetsBindingObserver {
|
||||
static const double _dayItemWidth = 44;
|
||||
static const double _dayItemGap = 12;
|
||||
static const double _hourHeight = 34;
|
||||
static const double _eventLeftOffset = 52;
|
||||
static const double _defaultHourHeight = 34.0;
|
||||
static const double _minHourHeight = 17.0;
|
||||
static const double _maxHourHeight = 68.0;
|
||||
|
||||
double _hourHeight = _defaultHourHeight;
|
||||
final Map<int, Offset> _activePointers = {};
|
||||
double? _pinchStartDistance;
|
||||
double _pinchStartHourHeight = _defaultHourHeight;
|
||||
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _selectedDate;
|
||||
@@ -36,10 +44,12 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
final ScrollController _dayStripController = ScrollController();
|
||||
Key _eventsKey = UniqueKey();
|
||||
List<ScheduleItemModel> _events = const [];
|
||||
String? _lastRoute;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_calendarManager = sl<CalendarStateManager>();
|
||||
|
||||
if (widget.resetToToday) {
|
||||
@@ -52,9 +62,22 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_scrollToSelectedDate();
|
||||
_lastRoute = GoRouterState.of(context).uri.toString();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final currentRoute = GoRouterState.of(context).uri.toString();
|
||||
if (_lastRoute != null && _lastRoute != currentRoute) {
|
||||
if (!currentRoute.contains('/events/')) {
|
||||
_loadEvents();
|
||||
}
|
||||
}
|
||||
_lastRoute = currentRoute;
|
||||
}
|
||||
|
||||
void _updateMonthDates() {
|
||||
_monthDates = monthDatesFor(_selectedDate);
|
||||
}
|
||||
@@ -71,47 +94,135 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_dayStripController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_loadEvents();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.todoBg,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: AppSpacing.lg,
|
||||
right: AppSpacing.lg,
|
||||
top: 2,
|
||||
bottom: 104,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildWeekStrip(),
|
||||
const SizedBox(height: 8),
|
||||
KeyedSubtree(
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
context.go('/calendar/month?date=${formatYmd(_selectedDate)}');
|
||||
}
|
||||
},
|
||||
child: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
top: 154,
|
||||
bottom: 84,
|
||||
child: Listener(
|
||||
onPointerDown: _handlePointerDown,
|
||||
onPointerMove: _handlePointerMove,
|
||||
onPointerUp: _handlePointerUp,
|
||||
onPointerCancel: _handlePointerCancel,
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: AppSpacing.lg,
|
||||
right: AppSpacing.lg,
|
||||
top: 2,
|
||||
),
|
||||
child: KeyedSubtree(
|
||||
key: _eventsKey,
|
||||
child: _buildTimelineBoard(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBottomDock(),
|
||||
],
|
||||
Positioned(top: 0, left: 0, right: 0, child: _buildHeader()),
|
||||
Positioned(top: 68, left: 0, right: 0, child: _buildWeekStrip()),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: _buildBottomDock(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _goToToday() {
|
||||
final today = DateTime.now();
|
||||
setState(() {
|
||||
_selectedDate = today;
|
||||
_hourHeight = _defaultHourHeight;
|
||||
});
|
||||
_calendarManager.setSelectedDate(today);
|
||||
_updateMonthDates();
|
||||
_scrollToSelectedDate(animate: true);
|
||||
_loadEvents();
|
||||
}
|
||||
|
||||
void _handlePointerDown(PointerDownEvent event) {
|
||||
_activePointers[event.pointer] = event.position;
|
||||
if (_activePointers.length == 2) {
|
||||
final pointers = _activePointers.values.toList(growable: false);
|
||||
_pinchStartDistance = (pointers[0] - pointers[1]).distance;
|
||||
_pinchStartHourHeight = _hourHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerMove(PointerMoveEvent event) {
|
||||
if (!_activePointers.containsKey(event.pointer)) {
|
||||
return;
|
||||
}
|
||||
_activePointers[event.pointer] = event.position;
|
||||
if (_activePointers.length != 2 || _pinchStartDistance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final pointers = _activePointers.values.toList(growable: false);
|
||||
final currentDistance = (pointers[0] - pointers[1]).distance;
|
||||
final startDistance = _pinchStartDistance!;
|
||||
if (startDistance <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final nextHeight =
|
||||
(_pinchStartHourHeight * (currentDistance / startDistance)).clamp(
|
||||
_minHourHeight,
|
||||
_maxHourHeight,
|
||||
);
|
||||
if ((nextHeight - _hourHeight).abs() < 0.1) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_hourHeight = nextHeight;
|
||||
});
|
||||
}
|
||||
|
||||
void _handlePointerUp(PointerUpEvent event) {
|
||||
_activePointers.remove(event.pointer);
|
||||
if (_activePointers.length < 2) {
|
||||
_pinchStartDistance = null;
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerCancel(PointerCancelEvent event) {
|
||||
_activePointers.remove(event.pointer);
|
||||
if (_activePointers.length < 2) {
|
||||
_pinchStartDistance = null;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return SizedBox(
|
||||
height: 68,
|
||||
@@ -151,6 +262,31 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (!isSameDay(_selectedDate, DateTime.now()))
|
||||
GestureDetector(
|
||||
onTap: _goToToday,
|
||||
child: Container(
|
||||
height: 36,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.messageBtnWrap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.messageBtnBorder),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'今天',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!isSameDay(_selectedDate, DateTime.now()))
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: () => CreateEventSheet.show(
|
||||
context,
|
||||
@@ -440,7 +576,7 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
bool isDisabled = false,
|
||||
}) {
|
||||
return SizedBox(
|
||||
height: 34,
|
||||
height: _hourHeight,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/notifications/local_notification_service.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../data/services/mock_calendar_service.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
@@ -161,7 +162,10 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('时间范围', timeStr),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('提醒时间', '开始前30分钟'),
|
||||
_buildDetailField(
|
||||
'提醒时间',
|
||||
_formatReminderText(event.metadata?.reminderMinutes),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildColorField(event.metadata?.color),
|
||||
const SizedBox(height: 14),
|
||||
@@ -176,8 +180,6 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
if (event.metadata?.notes != null) ...[
|
||||
_buildNotesField(event.metadata!.notes!),
|
||||
],
|
||||
const SizedBox(height: 14),
|
||||
_buildMetadataSection(event.metadata),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -186,6 +188,16 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
String _formatReminderText(int? reminderMinutes) {
|
||||
if (reminderMinutes == null) {
|
||||
return '无';
|
||||
}
|
||||
if (reminderMinutes == 0) {
|
||||
return '准时提醒';
|
||||
}
|
||||
return '开始前$reminderMinutes分钟';
|
||||
}
|
||||
|
||||
String _getWeekday(int weekday) {
|
||||
const weekdays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
return weekdays[weekday - 1];
|
||||
@@ -290,6 +302,9 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await sl<CalendarService>().deleteEvent(widget.eventId);
|
||||
await sl<LocalNotificationService>().cancelEventReminder(
|
||||
widget.eventId,
|
||||
);
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
@@ -385,40 +400,6 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMetadataSection(ScheduleMetadata? metadata) {
|
||||
final raw = metadata?.raw ?? const <String, dynamic>{};
|
||||
if (raw.isEmpty) {
|
||||
return _buildDetailField('metadata', '无');
|
||||
}
|
||||
final rows = <String>[];
|
||||
raw.forEach((key, value) {
|
||||
rows.add('$key: $value');
|
||||
});
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'metadata',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
...rows.map(
|
||||
(row) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(
|
||||
row,
|
||||
style: const TextStyle(fontSize: 13, color: AppColors.slate700),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Color _parseColor(String? hex) {
|
||||
if (hex == null || hex.isEmpty) return AppColors.blue600;
|
||||
try {
|
||||
|
||||
@@ -20,16 +20,19 @@ class CalendarMonthScreen extends StatefulWidget {
|
||||
State<CalendarMonthScreen> createState() => _CalendarMonthScreenState();
|
||||
}
|
||||
|
||||
class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
class _CalendarMonthScreenState extends State<CalendarMonthScreen>
|
||||
with WidgetsBindingObserver {
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _currentMonth;
|
||||
late DateTime _selectedDate;
|
||||
Key _eventsKey = UniqueKey();
|
||||
final Map<String, List<ScheduleItemModel>> _eventsByDay = {};
|
||||
String? _lastRoute;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_calendarManager = sl<CalendarStateManager>();
|
||||
|
||||
if (widget.resetToToday) {
|
||||
@@ -40,6 +43,22 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
_selectedDate = savedDate;
|
||||
_currentMonth = DateTime(savedDate.year, savedDate.month, 1);
|
||||
_loadMonthEvents();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_lastRoute = GoRouterState.of(context).uri.toString();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final currentRoute = GoRouterState.of(context).uri.toString();
|
||||
if (_lastRoute != null && _lastRoute != currentRoute) {
|
||||
if (!currentRoute.contains('/events/')) {
|
||||
_loadMonthEvents();
|
||||
}
|
||||
}
|
||||
_lastRoute = currentRoute;
|
||||
}
|
||||
|
||||
Future<void> _loadMonthEvents() async {
|
||||
@@ -64,24 +83,45 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_loadMonthEvents();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.todoBg,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 84),
|
||||
child: _buildMonthContent(),
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
context.go('/home');
|
||||
}
|
||||
},
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 84),
|
||||
child: _buildMonthContent(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBottomDock(),
|
||||
],
|
||||
_buildBottomDock(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/notifications/local_notification_service.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
import '../../data/services/mock_calendar_service.dart';
|
||||
@@ -63,6 +64,7 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
DateTime? _endDate;
|
||||
DateTime? _endTime;
|
||||
String _selectedColor = '#3B82F6';
|
||||
int? _reminderMinutes = 15;
|
||||
bool _saving = false;
|
||||
List<Attachment> _attachments = const [];
|
||||
|
||||
@@ -84,11 +86,13 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
_endDate = event.endAt;
|
||||
_endTime = event.endAt;
|
||||
_selectedColor = event.metadata?.color ?? '#3B82F6';
|
||||
_reminderMinutes = event.metadata?.reminderMinutes ?? 15;
|
||||
_attachments = List<Attachment>.from(
|
||||
event.metadata?.attachments ?? const [],
|
||||
);
|
||||
} else {
|
||||
final now = widget.initialDate ?? DateTime.now();
|
||||
final now =
|
||||
widget.initialDate ?? _roundToNearestMinute(DateTime.now(), 5);
|
||||
_startDate = now;
|
||||
_startTime = now;
|
||||
_endDate = now;
|
||||
@@ -108,6 +112,11 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
DateTime _roundToNearestMinute(DateTime dt, int interval) {
|
||||
final minute = (dt.minute / interval).round() * interval;
|
||||
return DateTime(dt.year, dt.month, dt.day, dt.hour, minute % 60);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -254,6 +263,8 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
const SizedBox(height: 20),
|
||||
_buildTextField('地点', _locationController, '请输入地点'),
|
||||
const SizedBox(height: 20),
|
||||
_buildReminderPicker(),
|
||||
const SizedBox(height: 20),
|
||||
_buildColorPicker(),
|
||||
const SizedBox(height: 20),
|
||||
_buildAttachmentsSection(),
|
||||
@@ -706,6 +717,68 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReminderPicker() {
|
||||
const options = <int?>[null, 0, 5, 10, 15, 30, 60, 120];
|
||||
String labelOf(int? value) {
|
||||
if (value == null) {
|
||||
return '无提醒';
|
||||
}
|
||||
if (value == 0) {
|
||||
return '准时提醒';
|
||||
}
|
||||
return '开始前$value分钟';
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'提醒时间',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<int?>(
|
||||
value: _reminderMinutes,
|
||||
isExpanded: true,
|
||||
items: options
|
||||
.map(
|
||||
(value) => DropdownMenuItem<int?>(
|
||||
value: value,
|
||||
child: Text(
|
||||
labelOf(value),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_reminderMinutes = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _saveEvent() async {
|
||||
if (_titleController.text.trim().isEmpty || _saving) return;
|
||||
setState(() {
|
||||
@@ -739,6 +812,7 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
notes: _notesController.text.trim().isNotEmpty
|
||||
? _notesController.text.trim()
|
||||
: null,
|
||||
reminderMinutes: _reminderMinutes,
|
||||
attachments: _attachments,
|
||||
version: widget.editingEvent?.metadata?.version ?? 1,
|
||||
);
|
||||
@@ -758,22 +832,21 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
|
||||
try {
|
||||
final service = sl<CalendarService>();
|
||||
debugPrint('CalendarService: $service');
|
||||
debugPrint('Is mock: ${service.runtimeType}');
|
||||
final notificationService = sl<LocalNotificationService>();
|
||||
late final ScheduleItemModel saved;
|
||||
|
||||
if (_isEditing) {
|
||||
await service.updateEvent(event);
|
||||
saved = await service.updateEvent(event);
|
||||
} else {
|
||||
await service.addEvent(event);
|
||||
saved = await service.addEvent(event);
|
||||
}
|
||||
await notificationService.upsertEventReminder(saved);
|
||||
|
||||
widget.onSaved?.call();
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
debugPrint('Save error: $e');
|
||||
debugPrint('Stack: $stack');
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
|
||||
@@ -45,13 +45,21 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.todoBg,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(child: _buildContent()),
|
||||
_buildBottomDock(),
|
||||
],
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
context.go('/home');
|
||||
}
|
||||
},
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(child: _buildContent()),
|
||||
_buildBottomDock(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -4,14 +4,19 @@ import 'core/config/env.dart';
|
||||
import 'core/di/injection.dart';
|
||||
import 'core/router/app_router.dart';
|
||||
import 'core/theme/app_theme.dart';
|
||||
import 'core/notifications/local_notification_service.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';
|
||||
import 'features/calendar/data/services/mock_calendar_service.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await configureDependencies();
|
||||
|
||||
final notificationService = sl<LocalNotificationService>();
|
||||
await notificationService.initialize();
|
||||
|
||||
final authBloc = sl<AuthBloc>();
|
||||
|
||||
if (Env.isMockApi) {
|
||||
@@ -24,6 +29,15 @@ void main() async {
|
||||
authBloc.add(AuthStarted());
|
||||
}
|
||||
|
||||
try {
|
||||
final now = DateTime.now();
|
||||
final end = now.add(const Duration(days: 90));
|
||||
final events = await sl<CalendarService>().getEventsForRange(now, end);
|
||||
await notificationService.rebuildUpcomingReminders(events);
|
||||
} catch (_) {
|
||||
// ignore startup sync failures
|
||||
}
|
||||
|
||||
runApp(LinksyApp(authBloc: authBloc));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ dependencies:
|
||||
shared_preferences: ^2.2.2
|
||||
json_annotation: ^4.8.1
|
||||
record: ^6.1.1
|
||||
flutter_local_notifications: ^17.2.4
|
||||
timezone: ^0.9.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
@@ -22,6 +22,7 @@ void main() {
|
||||
'color': '#4F46E5',
|
||||
'location': '会议室A',
|
||||
'notes': '带电脑',
|
||||
'reminder_minutes': 15,
|
||||
'attachments': [
|
||||
{
|
||||
'name': '议程文档',
|
||||
@@ -52,6 +53,7 @@ void main() {
|
||||
expect(result, hasLength(1));
|
||||
expect(result.first.metadata?.attachments, hasLength(1));
|
||||
expect(result.first.metadata?.raw['new_field'], 'future');
|
||||
expect(result.first.metadata?.reminderMinutes, 15);
|
||||
expect(result.first.startAt.isUtc, isFalse);
|
||||
});
|
||||
|
||||
@@ -60,6 +62,7 @@ void main() {
|
||||
client.registerHandler('/api/v1/schedule-items', 'POST', (request) {
|
||||
final body = request.data as Map<String, dynamic>;
|
||||
expect(body['metadata']['version'], 1);
|
||||
expect(body['metadata']['reminder_minutes'], 15);
|
||||
expect(body['metadata']['attachments'], isA<List<dynamic>>());
|
||||
return {
|
||||
'id': 'evt_2',
|
||||
@@ -83,6 +86,7 @@ void main() {
|
||||
location: '线上',
|
||||
notes: '准备 demo',
|
||||
attachments: [Attachment(name: 'PRD', type: 'document')],
|
||||
reminderMinutes: 15,
|
||||
version: 1,
|
||||
),
|
||||
),
|
||||
@@ -100,6 +104,7 @@ void main() {
|
||||
final body = request.data as Map<String, dynamic>;
|
||||
final metadata = body['metadata'] as Map<String, dynamic>;
|
||||
expect(metadata.containsKey('new_field'), isFalse);
|
||||
expect(metadata['reminder_minutes'], 30);
|
||||
return {
|
||||
'id': 'evt_3',
|
||||
...body,
|
||||
@@ -121,6 +126,7 @@ void main() {
|
||||
'notes': '更新周报',
|
||||
'attachments': const [],
|
||||
'version': 1,
|
||||
'reminder_minutes': 30,
|
||||
'new_field': 'future',
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:social_app/core/di/injection.dart';
|
||||
import 'package:social_app/features/calendar/data/models/schedule_item_model.dart';
|
||||
import 'package:social_app/features/calendar/data/services/mock_calendar_service.dart';
|
||||
import 'package:social_app/features/calendar/ui/screens/calendar_event_detail_screen.dart';
|
||||
|
||||
class _FakeCalendarService extends CalendarService {
|
||||
final ScheduleItemModel? event;
|
||||
|
||||
_FakeCalendarService({required this.event}) : super(apiClient: null);
|
||||
|
||||
@override
|
||||
Future<ScheduleItemModel?> getEventById(String id) async {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
final getIt = GetIt.instance;
|
||||
|
||||
setUp(() async {
|
||||
await getIt.reset();
|
||||
});
|
||||
|
||||
testWidgets('详情页显示结构化提醒时间并不显示metadata原样区块', (tester) async {
|
||||
sl.registerSingleton<CalendarService>(
|
||||
_FakeCalendarService(
|
||||
event: ScheduleItemModel(
|
||||
id: 'evt_1',
|
||||
title: '评审会',
|
||||
startAt: DateTime(2026, 3, 11, 15, 0),
|
||||
endAt: DateTime(2026, 3, 11, 16, 0),
|
||||
metadata: ScheduleMetadata(
|
||||
color: '#4F46E5',
|
||||
location: '会议室A',
|
||||
reminderMinutes: 15,
|
||||
version: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: CalendarEventDetailScreen(eventId: 'evt_1')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('提醒时间'), findsOneWidget);
|
||||
expect(find.text('开始前15分钟'), findsOneWidget);
|
||||
expect(find.text('metadata'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('提醒分钟为空时显示无', (tester) async {
|
||||
sl.registerSingleton<CalendarService>(
|
||||
_FakeCalendarService(
|
||||
event: ScheduleItemModel(
|
||||
id: 'evt_2',
|
||||
title: '同步会',
|
||||
startAt: DateTime(2026, 3, 12, 10, 0),
|
||||
metadata: ScheduleMetadata(version: 1),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: CalendarEventDetailScreen(eventId: 'evt_2')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('提醒时间'), findsOneWidget);
|
||||
expect(find.text('无'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user