feat: 重构 memory 系统,支持 user memory 和 work memory 分离
This commit is contained in:
@@ -226,7 +226,6 @@ class ToolCallResultEvent extends AgUiEvent {
|
||||
required this.toolName,
|
||||
required this.resultSummary,
|
||||
required this.status,
|
||||
required this.uiSchema,
|
||||
}) : super(type: AgUiEventType.toolCallResult);
|
||||
|
||||
final String messageId;
|
||||
@@ -234,7 +233,6 @@ class ToolCallResultEvent extends AgUiEvent {
|
||||
final String toolName;
|
||||
final String resultSummary;
|
||||
final String status;
|
||||
final Map<String, dynamic>? uiSchema;
|
||||
|
||||
factory ToolCallResultEvent.fromJson(Map<String, dynamic> json) =>
|
||||
ToolCallResultEvent(
|
||||
@@ -243,7 +241,6 @@ class ToolCallResultEvent extends AgUiEvent {
|
||||
toolName: _asString(json['tool_name']),
|
||||
resultSummary: _asString(json['result']),
|
||||
status: _asString(json['status'], fallback: 'success'),
|
||||
uiSchema: _asMap(json['ui_schema']),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -363,7 +363,7 @@ class AgUiService {
|
||||
],
|
||||
'tools': <Map<String, dynamic>>[],
|
||||
'context': <Map<String, dynamic>>[],
|
||||
'forwardedProps': <String, dynamic>{},
|
||||
'forwardedProps': <String, dynamic>{'runtime_mode': 'chat'},
|
||||
},
|
||||
uploadedAttachments: uploadedAttachments,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,951 @@
|
||||
class PersonMeta {
|
||||
final String? source;
|
||||
final double? confidence;
|
||||
final DateTime? lastUpdatedAt;
|
||||
|
||||
PersonMeta({this.source, this.confidence, this.lastUpdatedAt});
|
||||
|
||||
factory PersonMeta.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return PersonMeta();
|
||||
return PersonMeta(
|
||||
source: json['source'] as String?,
|
||||
confidence: (json['confidence'] as num?)?.toDouble(),
|
||||
lastUpdatedAt: json['last_updated_at'] != null
|
||||
? DateTime.parse(json['last_updated_at'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'source': source,
|
||||
'confidence': confidence,
|
||||
'last_updated_at': lastUpdatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
class Person {
|
||||
final String name;
|
||||
final String? relationship;
|
||||
final String? role;
|
||||
final String? preferredContactChannel;
|
||||
final String? notes;
|
||||
final PersonMeta? meta;
|
||||
|
||||
Person({
|
||||
required this.name,
|
||||
this.relationship,
|
||||
this.role,
|
||||
this.preferredContactChannel,
|
||||
this.notes,
|
||||
this.meta,
|
||||
});
|
||||
|
||||
factory Person.fromJson(Map<String, dynamic> json) {
|
||||
return Person(
|
||||
name: json['name'] as String? ?? '',
|
||||
relationship: json['relationship'] as String?,
|
||||
role: json['role'] as String?,
|
||||
preferredContactChannel: json['preferred_contact_channel'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
meta: json['meta'] != null
|
||||
? PersonMeta.fromJson(json['meta'] as Map<String, dynamic>?)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'relationship': relationship,
|
||||
'role': role,
|
||||
'preferred_contact_channel': preferredContactChannel,
|
||||
'notes': notes,
|
||||
'meta': meta?.toJson(),
|
||||
};
|
||||
|
||||
Person copyWith({
|
||||
String? name,
|
||||
String? relationship,
|
||||
String? role,
|
||||
String? preferredContactChannel,
|
||||
String? notes,
|
||||
PersonMeta? meta,
|
||||
}) {
|
||||
return Person(
|
||||
name: name ?? this.name,
|
||||
relationship: relationship ?? this.relationship,
|
||||
role: role ?? this.role,
|
||||
preferredContactChannel:
|
||||
preferredContactChannel ?? this.preferredContactChannel,
|
||||
notes: notes ?? this.notes,
|
||||
meta: meta ?? this.meta,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PlaceMeta {
|
||||
final String? source;
|
||||
final double? confidence;
|
||||
final DateTime? lastUpdatedAt;
|
||||
|
||||
PlaceMeta({this.source, this.confidence, this.lastUpdatedAt});
|
||||
|
||||
factory PlaceMeta.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return PlaceMeta();
|
||||
return PlaceMeta(
|
||||
source: json['source'] as String?,
|
||||
confidence: (json['confidence'] as num?)?.toDouble(),
|
||||
lastUpdatedAt: json['last_updated_at'] != null
|
||||
? DateTime.parse(json['last_updated_at'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'source': source,
|
||||
'confidence': confidence,
|
||||
'last_updated_at': lastUpdatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
class Place {
|
||||
final String name;
|
||||
final String? category;
|
||||
final String? address;
|
||||
final String? timezone;
|
||||
final int? commuteMinutes;
|
||||
final String? preference;
|
||||
final String? notes;
|
||||
final PlaceMeta? meta;
|
||||
|
||||
Place({
|
||||
required this.name,
|
||||
this.category,
|
||||
this.address,
|
||||
this.timezone,
|
||||
this.commuteMinutes,
|
||||
this.preference,
|
||||
this.notes,
|
||||
this.meta,
|
||||
});
|
||||
|
||||
factory Place.fromJson(Map<String, dynamic> json) {
|
||||
return Place(
|
||||
name: json['name'] as String? ?? '',
|
||||
category: json['category'] as String?,
|
||||
address: json['address'] as String?,
|
||||
timezone: json['timezone'] as String?,
|
||||
commuteMinutes: json['commute_minutes'] as int?,
|
||||
preference: json['preference'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
meta: json['meta'] != null
|
||||
? PlaceMeta.fromJson(json['meta'] as Map<String, dynamic>?)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'category': category,
|
||||
'address': address,
|
||||
'timezone': timezone,
|
||||
'commute_minutes': commuteMinutes,
|
||||
'preference': preference,
|
||||
'notes': notes,
|
||||
'meta': meta?.toJson(),
|
||||
};
|
||||
|
||||
Place copyWith({
|
||||
String? name,
|
||||
String? category,
|
||||
String? address,
|
||||
String? timezone,
|
||||
int? commuteMinutes,
|
||||
String? preference,
|
||||
String? notes,
|
||||
PlaceMeta? meta,
|
||||
}) {
|
||||
return Place(
|
||||
name: name ?? this.name,
|
||||
category: category ?? this.category,
|
||||
address: address ?? this.address,
|
||||
timezone: timezone ?? this.timezone,
|
||||
commuteMinutes: commuteMinutes ?? this.commuteMinutes,
|
||||
preference: preference ?? this.preference,
|
||||
notes: notes ?? this.notes,
|
||||
meta: meta ?? this.meta,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UserPreferences {
|
||||
final String? communicationStyle;
|
||||
final List<String> languagePreference;
|
||||
final String? locationPreference;
|
||||
final String? workLifestyle;
|
||||
final List<String> notificationPreference;
|
||||
|
||||
UserPreferences({
|
||||
this.communicationStyle,
|
||||
this.languagePreference = const [],
|
||||
this.locationPreference,
|
||||
this.workLifestyle,
|
||||
this.notificationPreference = const [],
|
||||
});
|
||||
|
||||
factory UserPreferences.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return UserPreferences();
|
||||
return UserPreferences(
|
||||
communicationStyle: json['communication_style'] as String?,
|
||||
languagePreference:
|
||||
(json['language_preference'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
locationPreference: json['location_preference'] as String?,
|
||||
workLifestyle: json['work_lifestyle'] as String?,
|
||||
notificationPreference:
|
||||
(json['notification_preference'] as List<dynamic>?)?.cast<String>() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'communication_style': communicationStyle,
|
||||
'language_preference': languagePreference,
|
||||
'location_preference': locationPreference,
|
||||
'work_lifestyle': workLifestyle,
|
||||
'notification_preference': notificationPreference,
|
||||
};
|
||||
|
||||
UserPreferences copyWith({
|
||||
String? communicationStyle,
|
||||
List<String>? languagePreference,
|
||||
String? locationPreference,
|
||||
String? workLifestyle,
|
||||
List<String>? notificationPreference,
|
||||
}) {
|
||||
return UserPreferences(
|
||||
communicationStyle: communicationStyle ?? this.communicationStyle,
|
||||
languagePreference: languagePreference ?? this.languagePreference,
|
||||
locationPreference: locationPreference ?? this.locationPreference,
|
||||
workLifestyle: workLifestyle ?? this.workLifestyle,
|
||||
notificationPreference:
|
||||
notificationPreference ?? this.notificationPreference,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimeWindow {
|
||||
final List<String> weekdays;
|
||||
final String? start;
|
||||
final String? end;
|
||||
|
||||
TimeWindow({this.weekdays = const [], this.start, this.end});
|
||||
|
||||
factory TimeWindow.fromJson(Map<String, dynamic> json) {
|
||||
return TimeWindow(
|
||||
weekdays: (json['weekdays'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
start: json['start'] as String?,
|
||||
end: json['end'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'weekdays': weekdays,
|
||||
'start': start,
|
||||
'end': end,
|
||||
};
|
||||
}
|
||||
|
||||
class SchedulingPreferences {
|
||||
final List<TimeWindow> productiveWindows;
|
||||
final List<TimeWindow> preferredMeetingWindows;
|
||||
final List<TimeWindow> noMeetingWindows;
|
||||
final List<TimeWindow> deepWorkWindows;
|
||||
final List<int> preferredMeetingDurationMinutes;
|
||||
final int? meetingBufferMinutes;
|
||||
final int? maxMeetingsPerDay;
|
||||
final String? notes;
|
||||
|
||||
SchedulingPreferences({
|
||||
this.productiveWindows = const [],
|
||||
this.preferredMeetingWindows = const [],
|
||||
this.noMeetingWindows = const [],
|
||||
this.deepWorkWindows = const [],
|
||||
this.preferredMeetingDurationMinutes = const [30, 60],
|
||||
this.meetingBufferMinutes,
|
||||
this.maxMeetingsPerDay,
|
||||
this.notes,
|
||||
});
|
||||
|
||||
factory SchedulingPreferences.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return SchedulingPreferences();
|
||||
return SchedulingPreferences(
|
||||
productiveWindows:
|
||||
(json['productive_windows'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
preferredMeetingWindows:
|
||||
(json['preferred_meeting_windows'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
noMeetingWindows:
|
||||
(json['no_meeting_windows'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
deepWorkWindows:
|
||||
(json['deep_work_windows'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
preferredMeetingDurationMinutes:
|
||||
(json['preferred_meeting_duration_minutes'] as List<dynamic>?)
|
||||
?.cast<int>() ??
|
||||
[30, 60],
|
||||
meetingBufferMinutes: json['meeting_buffer_minutes'] as int?,
|
||||
maxMeetingsPerDay: json['max_meetings_per_day'] as int?,
|
||||
notes: json['notes'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'productive_windows': productiveWindows.map((e) => e.toJson()).toList(),
|
||||
'preferred_meeting_windows': preferredMeetingWindows
|
||||
.map((e) => e.toJson())
|
||||
.toList(),
|
||||
'no_meeting_windows': noMeetingWindows.map((e) => e.toJson()).toList(),
|
||||
'deep_work_windows': deepWorkWindows.map((e) => e.toJson()).toList(),
|
||||
'preferred_meeting_duration_minutes': preferredMeetingDurationMinutes,
|
||||
'meeting_buffer_minutes': meetingBufferMinutes,
|
||||
'max_meetings_per_day': maxMeetingsPerDay,
|
||||
'notes': notes,
|
||||
};
|
||||
|
||||
SchedulingPreferences copyWith({
|
||||
List<TimeWindow>? productiveWindows,
|
||||
List<TimeWindow>? preferredMeetingWindows,
|
||||
List<TimeWindow>? noMeetingWindows,
|
||||
List<TimeWindow>? deepWorkWindows,
|
||||
List<int>? preferredMeetingDurationMinutes,
|
||||
int? meetingBufferMinutes,
|
||||
int? maxMeetingsPerDay,
|
||||
String? notes,
|
||||
}) {
|
||||
return SchedulingPreferences(
|
||||
productiveWindows: productiveWindows ?? this.productiveWindows,
|
||||
preferredMeetingWindows:
|
||||
preferredMeetingWindows ?? this.preferredMeetingWindows,
|
||||
noMeetingWindows: noMeetingWindows ?? this.noMeetingWindows,
|
||||
deepWorkWindows: deepWorkWindows ?? this.deepWorkWindows,
|
||||
preferredMeetingDurationMinutes:
|
||||
preferredMeetingDurationMinutes ??
|
||||
this.preferredMeetingDurationMinutes,
|
||||
meetingBufferMinutes: meetingBufferMinutes ?? this.meetingBufferMinutes,
|
||||
maxMeetingsPerDay: maxMeetingsPerDay ?? this.maxMeetingsPerDay,
|
||||
notes: notes ?? this.notes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RecurringRoutineMeta {
|
||||
final String? source;
|
||||
final double? confidence;
|
||||
final DateTime? lastUpdatedAt;
|
||||
|
||||
RecurringRoutineMeta({this.source, this.confidence, this.lastUpdatedAt});
|
||||
|
||||
factory RecurringRoutineMeta.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return RecurringRoutineMeta();
|
||||
return RecurringRoutineMeta(
|
||||
source: json['source'] as String?,
|
||||
confidence: (json['confidence'] as num?)?.toDouble(),
|
||||
lastUpdatedAt: json['last_updated_at'] != null
|
||||
? DateTime.parse(json['last_updated_at'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'source': source,
|
||||
'confidence': confidence,
|
||||
'last_updated_at': lastUpdatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
class RecurringRoutine {
|
||||
final String name;
|
||||
final String? description;
|
||||
final String? cadence;
|
||||
final List<TimeWindow> timeWindows;
|
||||
final String? importance;
|
||||
final RecurringRoutineMeta? meta;
|
||||
|
||||
RecurringRoutine({
|
||||
required this.name,
|
||||
this.description,
|
||||
this.cadence,
|
||||
this.timeWindows = const [],
|
||||
this.importance,
|
||||
this.meta,
|
||||
});
|
||||
|
||||
factory RecurringRoutine.fromJson(Map<String, dynamic> json) {
|
||||
return RecurringRoutine(
|
||||
name: json['name'] as String? ?? '',
|
||||
description: json['description'] as String?,
|
||||
cadence: json['cadence'] as String?,
|
||||
timeWindows:
|
||||
(json['time_windows'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
importance: json['importance'] as String?,
|
||||
meta: json['meta'] != null
|
||||
? RecurringRoutineMeta.fromJson(json['meta'] as Map<String, dynamic>?)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'description': description,
|
||||
'cadence': cadence,
|
||||
'time_windows': timeWindows.map((e) => e.toJson()).toList(),
|
||||
'importance': importance,
|
||||
'meta': meta?.toJson(),
|
||||
};
|
||||
|
||||
RecurringRoutine copyWith({
|
||||
String? name,
|
||||
String? description,
|
||||
String? cadence,
|
||||
List<TimeWindow>? timeWindows,
|
||||
String? importance,
|
||||
RecurringRoutineMeta? meta,
|
||||
}) {
|
||||
return RecurringRoutine(
|
||||
name: name ?? this.name,
|
||||
description: description ?? this.description,
|
||||
cadence: cadence ?? this.cadence,
|
||||
timeWindows: timeWindows ?? this.timeWindows,
|
||||
importance: importance ?? this.importance,
|
||||
meta: meta ?? this.meta,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UserMemoryContent {
|
||||
final String? occupation;
|
||||
final String? timezone;
|
||||
final String? primaryLanguage;
|
||||
final List<Person> people;
|
||||
final List<Place> places;
|
||||
final UserPreferences preferences;
|
||||
final SchedulingPreferences schedulingPreferences;
|
||||
final List<String> interests;
|
||||
final List<String> avoidTopics;
|
||||
final List<String> customRules;
|
||||
final List<RecurringRoutine> recurringRoutines;
|
||||
|
||||
UserMemoryContent({
|
||||
this.occupation,
|
||||
this.timezone,
|
||||
this.primaryLanguage,
|
||||
this.people = const [],
|
||||
this.places = const [],
|
||||
UserPreferences? preferences,
|
||||
SchedulingPreferences? schedulingPreferences,
|
||||
this.interests = const [],
|
||||
this.avoidTopics = const [],
|
||||
this.customRules = const [],
|
||||
this.recurringRoutines = const [],
|
||||
}) : preferences = preferences ?? UserPreferences(),
|
||||
schedulingPreferences = schedulingPreferences ?? SchedulingPreferences();
|
||||
|
||||
factory UserMemoryContent.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return UserMemoryContent();
|
||||
return UserMemoryContent(
|
||||
occupation: json['occupation'] as String?,
|
||||
timezone: json['timezone'] as String?,
|
||||
primaryLanguage: json['primary_language'] as String?,
|
||||
people:
|
||||
(json['people'] as List<dynamic>?)
|
||||
?.map((e) => Person.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
places:
|
||||
(json['places'] as List<dynamic>?)
|
||||
?.map((e) => Place.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
preferences: UserPreferences.fromJson(
|
||||
json['preferences'] as Map<String, dynamic>?,
|
||||
),
|
||||
schedulingPreferences: SchedulingPreferences.fromJson(
|
||||
json['scheduling_preferences'] as Map<String, dynamic>?,
|
||||
),
|
||||
interests: (json['interests'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
avoidTopics:
|
||||
(json['avoid_topics'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
customRules:
|
||||
(json['custom_rules'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
recurringRoutines:
|
||||
(json['recurring_routines'] as List<dynamic>?)
|
||||
?.map((e) => RecurringRoutine.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'occupation': occupation,
|
||||
'timezone': timezone,
|
||||
'primary_language': primaryLanguage,
|
||||
'people': people.map((e) => e.toJson()).toList(),
|
||||
'places': places.map((e) => e.toJson()).toList(),
|
||||
'preferences': preferences.toJson(),
|
||||
'scheduling_preferences': schedulingPreferences.toJson(),
|
||||
'interests': interests,
|
||||
'avoid_topics': avoidTopics,
|
||||
'custom_rules': customRules,
|
||||
'recurring_routines': recurringRoutines.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
UserMemoryContent copyWith({
|
||||
String? occupation,
|
||||
String? timezone,
|
||||
String? primaryLanguage,
|
||||
List<Person>? people,
|
||||
List<Place>? places,
|
||||
UserPreferences? preferences,
|
||||
SchedulingPreferences? schedulingPreferences,
|
||||
List<String>? interests,
|
||||
List<String>? avoidTopics,
|
||||
List<String>? customRules,
|
||||
List<RecurringRoutine>? recurringRoutines,
|
||||
}) {
|
||||
return UserMemoryContent(
|
||||
occupation: occupation ?? this.occupation,
|
||||
timezone: timezone ?? this.timezone,
|
||||
primaryLanguage: primaryLanguage ?? this.primaryLanguage,
|
||||
people: people ?? this.people,
|
||||
places: places ?? this.places,
|
||||
preferences: preferences ?? this.preferences,
|
||||
schedulingPreferences:
|
||||
schedulingPreferences ?? this.schedulingPreferences,
|
||||
interests: interests ?? this.interests,
|
||||
avoidTopics: avoidTopics ?? this.avoidTopics,
|
||||
customRules: customRules ?? this.customRules,
|
||||
recurringRoutines: recurringRoutines ?? this.recurringRoutines,
|
||||
);
|
||||
}
|
||||
|
||||
String get summary {
|
||||
final parts = <String>[];
|
||||
if (occupation != null && occupation!.isNotEmpty) {
|
||||
parts.add(occupation!);
|
||||
}
|
||||
if (people.isNotEmpty) {
|
||||
parts.add('${people.length} 位联系人');
|
||||
}
|
||||
if (places.isNotEmpty) {
|
||||
parts.add('${places.length} 个地点');
|
||||
}
|
||||
if (interests.isNotEmpty) {
|
||||
parts.add('${interests.length} 个兴趣');
|
||||
}
|
||||
return parts.isEmpty ? '暂无信息' : parts.join(' · ');
|
||||
}
|
||||
}
|
||||
|
||||
class KeyMilestone {
|
||||
final String name;
|
||||
final DateTime? dueDate;
|
||||
final String? status;
|
||||
final String? notes;
|
||||
|
||||
KeyMilestone({required this.name, this.dueDate, this.status, this.notes});
|
||||
|
||||
factory KeyMilestone.fromJson(Map<String, dynamic> json) {
|
||||
return KeyMilestone(
|
||||
name: json['name'] as String? ?? '',
|
||||
dueDate: json['due_date'] != null
|
||||
? DateTime.parse(json['due_date'] as String)
|
||||
: null,
|
||||
status: json['status'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'due_date': dueDate?.toIso8601String().split('T').first,
|
||||
'status': status,
|
||||
'notes': notes,
|
||||
};
|
||||
}
|
||||
|
||||
class CurrentProject {
|
||||
final String name;
|
||||
final String? description;
|
||||
final String? status;
|
||||
final String? priority;
|
||||
final DateTime? deadline;
|
||||
final List<String> collaborators;
|
||||
final List<KeyMilestone> keyMilestones;
|
||||
final String? notes;
|
||||
|
||||
CurrentProject({
|
||||
required this.name,
|
||||
this.description,
|
||||
this.status,
|
||||
this.priority,
|
||||
this.deadline,
|
||||
this.collaborators = const [],
|
||||
this.keyMilestones = const [],
|
||||
this.notes,
|
||||
});
|
||||
|
||||
factory CurrentProject.fromJson(Map<String, dynamic> json) {
|
||||
return CurrentProject(
|
||||
name: json['name'] as String? ?? '',
|
||||
description: json['description'] as String?,
|
||||
status: json['status'] as String?,
|
||||
priority: json['priority'] as String?,
|
||||
deadline: json['deadline'] != null
|
||||
? DateTime.parse(json['deadline'] as String)
|
||||
: null,
|
||||
collaborators:
|
||||
(json['collaborators'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
keyMilestones:
|
||||
(json['key_milestones'] as List<dynamic>?)
|
||||
?.map((e) => KeyMilestone.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
notes: json['notes'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'description': description,
|
||||
'status': status,
|
||||
'priority': priority,
|
||||
'deadline': deadline?.toIso8601String().split('T').first,
|
||||
'collaborators': collaborators,
|
||||
'key_milestones': keyMilestones.map((e) => e.toJson()).toList(),
|
||||
'notes': notes,
|
||||
};
|
||||
|
||||
CurrentProject copyWith({
|
||||
String? name,
|
||||
String? description,
|
||||
String? status,
|
||||
String? priority,
|
||||
DateTime? deadline,
|
||||
List<String>? collaborators,
|
||||
List<KeyMilestone>? keyMilestones,
|
||||
String? notes,
|
||||
}) {
|
||||
return CurrentProject(
|
||||
name: name ?? this.name,
|
||||
description: description ?? this.description,
|
||||
status: status ?? this.status,
|
||||
priority: priority ?? this.priority,
|
||||
deadline: deadline ?? this.deadline,
|
||||
collaborators: collaborators ?? this.collaborators,
|
||||
keyMilestones: keyMilestones ?? this.keyMilestones,
|
||||
notes: notes ?? this.notes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WorkHabits {
|
||||
final List<TimeWindow> availableHours;
|
||||
final List<TimeWindow> deepWorkBlocks;
|
||||
final List<TimeWindow> preferredMeetingWindows;
|
||||
final List<TimeWindow> noMeetingWindows;
|
||||
final List<int> preferredMeetingDurationMinutes;
|
||||
final String? notificationChannel;
|
||||
final String? notes;
|
||||
|
||||
WorkHabits({
|
||||
this.availableHours = const [],
|
||||
this.deepWorkBlocks = const [],
|
||||
this.preferredMeetingWindows = const [],
|
||||
this.noMeetingWindows = const [],
|
||||
this.preferredMeetingDurationMinutes = const [30, 60],
|
||||
this.notificationChannel,
|
||||
this.notes,
|
||||
});
|
||||
|
||||
factory WorkHabits.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return WorkHabits();
|
||||
return WorkHabits(
|
||||
availableHours:
|
||||
(json['available_hours'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
deepWorkBlocks:
|
||||
(json['deep_work_blocks'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
preferredMeetingWindows:
|
||||
(json['preferred_meeting_windows'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
noMeetingWindows:
|
||||
(json['no_meeting_windows'] as List<dynamic>?)
|
||||
?.map((e) => TimeWindow.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
preferredMeetingDurationMinutes:
|
||||
(json['preferred_meeting_duration_minutes'] as List<dynamic>?)
|
||||
?.cast<int>() ??
|
||||
[30, 60],
|
||||
notificationChannel: json['notification_channel'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'available_hours': availableHours.map((e) => e.toJson()).toList(),
|
||||
'deep_work_blocks': deepWorkBlocks.map((e) => e.toJson()).toList(),
|
||||
'preferred_meeting_windows': preferredMeetingWindows
|
||||
.map((e) => e.toJson())
|
||||
.toList(),
|
||||
'no_meeting_windows': noMeetingWindows.map((e) => e.toJson()).toList(),
|
||||
'preferred_meeting_duration_minutes': preferredMeetingDurationMinutes,
|
||||
'notification_channel': notificationChannel,
|
||||
'notes': notes,
|
||||
};
|
||||
|
||||
WorkHabits copyWith({
|
||||
List<TimeWindow>? availableHours,
|
||||
List<TimeWindow>? deepWorkBlocks,
|
||||
List<TimeWindow>? preferredMeetingWindows,
|
||||
List<TimeWindow>? noMeetingWindows,
|
||||
List<int>? preferredMeetingDurationMinutes,
|
||||
String? notificationChannel,
|
||||
String? notes,
|
||||
}) {
|
||||
return WorkHabits(
|
||||
availableHours: availableHours ?? this.availableHours,
|
||||
deepWorkBlocks: deepWorkBlocks ?? this.deepWorkBlocks,
|
||||
preferredMeetingWindows:
|
||||
preferredMeetingWindows ?? this.preferredMeetingWindows,
|
||||
noMeetingWindows: noMeetingWindows ?? this.noMeetingWindows,
|
||||
preferredMeetingDurationMinutes:
|
||||
preferredMeetingDurationMinutes ??
|
||||
this.preferredMeetingDurationMinutes,
|
||||
notificationChannel: notificationChannel ?? this.notificationChannel,
|
||||
notes: notes ?? this.notes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TeamMemberMeta {
|
||||
final String? source;
|
||||
final double? confidence;
|
||||
final DateTime? lastUpdatedAt;
|
||||
|
||||
TeamMemberMeta({this.source, this.confidence, this.lastUpdatedAt});
|
||||
|
||||
factory TeamMemberMeta.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return TeamMemberMeta();
|
||||
return TeamMemberMeta(
|
||||
source: json['source'] as String?,
|
||||
confidence: (json['confidence'] as num?)?.toDouble(),
|
||||
lastUpdatedAt: json['last_updated_at'] != null
|
||||
? DateTime.parse(json['last_updated_at'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'source': source,
|
||||
'confidence': confidence,
|
||||
'last_updated_at': lastUpdatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
class TeamMember {
|
||||
final String name;
|
||||
final String? role;
|
||||
final String? relationship;
|
||||
final String? preferredContactChannel;
|
||||
final String? notes;
|
||||
final TeamMemberMeta? meta;
|
||||
|
||||
TeamMember({
|
||||
required this.name,
|
||||
this.role,
|
||||
this.relationship,
|
||||
this.preferredContactChannel,
|
||||
this.notes,
|
||||
this.meta,
|
||||
});
|
||||
|
||||
factory TeamMember.fromJson(Map<String, dynamic> json) {
|
||||
return TeamMember(
|
||||
name: json['name'] as String? ?? '',
|
||||
role: json['role'] as String?,
|
||||
relationship: json['relationship'] as String?,
|
||||
preferredContactChannel: json['preferred_contact_channel'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
meta: json['meta'] != null
|
||||
? TeamMemberMeta.fromJson(json['meta'] as Map<String, dynamic>?)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'role': role,
|
||||
'relationship': relationship,
|
||||
'preferred_contact_channel': preferredContactChannel,
|
||||
'notes': notes,
|
||||
'meta': meta?.toJson(),
|
||||
};
|
||||
|
||||
TeamMember copyWith({
|
||||
String? name,
|
||||
String? role,
|
||||
String? relationship,
|
||||
String? preferredContactChannel,
|
||||
String? notes,
|
||||
TeamMemberMeta? meta,
|
||||
}) {
|
||||
return TeamMember(
|
||||
name: name ?? this.name,
|
||||
role: role ?? this.role,
|
||||
relationship: relationship ?? this.relationship,
|
||||
preferredContactChannel:
|
||||
preferredContactChannel ?? this.preferredContactChannel,
|
||||
notes: notes ?? this.notes,
|
||||
meta: meta ?? this.meta,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WorkProfileContent {
|
||||
final String? occupation;
|
||||
final List<String> expertise;
|
||||
final List<String> preferredTools;
|
||||
final List<CurrentProject> currentProjects;
|
||||
final WorkHabits workHabits;
|
||||
final List<TeamMember> teamMembers;
|
||||
final String? teamContext;
|
||||
final List<String> workRules;
|
||||
|
||||
WorkProfileContent({
|
||||
this.occupation,
|
||||
this.expertise = const [],
|
||||
this.preferredTools = const [],
|
||||
this.currentProjects = const [],
|
||||
WorkHabits? workHabits,
|
||||
this.teamMembers = const [],
|
||||
this.teamContext,
|
||||
this.workRules = const [],
|
||||
}) : workHabits = workHabits ?? WorkHabits();
|
||||
|
||||
factory WorkProfileContent.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return WorkProfileContent();
|
||||
return WorkProfileContent(
|
||||
occupation: json['occupation'] as String?,
|
||||
expertise: (json['expertise'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
preferredTools:
|
||||
(json['preferred_tools'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
currentProjects:
|
||||
(json['current_projects'] as List<dynamic>?)
|
||||
?.map((e) => CurrentProject.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
workHabits: WorkHabits.fromJson(
|
||||
json['work_habits'] as Map<String, dynamic>?,
|
||||
),
|
||||
teamMembers:
|
||||
(json['team_members'] as List<dynamic>?)
|
||||
?.map((e) => TeamMember.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
teamContext: json['team_context'] as String?,
|
||||
workRules: (json['work_rules'] as List<dynamic>?)?.cast<String>() ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'occupation': occupation,
|
||||
'expertise': expertise,
|
||||
'preferred_tools': preferredTools,
|
||||
'current_projects': currentProjects.map((e) => e.toJson()).toList(),
|
||||
'work_habits': workHabits.toJson(),
|
||||
'team_members': teamMembers.map((e) => e.toJson()).toList(),
|
||||
'team_context': teamContext,
|
||||
'work_rules': workRules,
|
||||
};
|
||||
|
||||
WorkProfileContent copyWith({
|
||||
String? occupation,
|
||||
List<String>? expertise,
|
||||
List<String>? preferredTools,
|
||||
List<CurrentProject>? currentProjects,
|
||||
WorkHabits? workHabits,
|
||||
List<TeamMember>? teamMembers,
|
||||
String? teamContext,
|
||||
List<String>? workRules,
|
||||
}) {
|
||||
return WorkProfileContent(
|
||||
occupation: occupation ?? this.occupation,
|
||||
expertise: expertise ?? this.expertise,
|
||||
preferredTools: preferredTools ?? this.preferredTools,
|
||||
currentProjects: currentProjects ?? this.currentProjects,
|
||||
workHabits: workHabits ?? this.workHabits,
|
||||
teamMembers: teamMembers ?? this.teamMembers,
|
||||
teamContext: teamContext ?? this.teamContext,
|
||||
workRules: workRules ?? this.workRules,
|
||||
);
|
||||
}
|
||||
|
||||
String get summary {
|
||||
final parts = <String>[];
|
||||
if (occupation != null && occupation!.isNotEmpty) {
|
||||
parts.add(occupation!);
|
||||
}
|
||||
if (expertise.isNotEmpty) {
|
||||
parts.add('${expertise.length} 项专长');
|
||||
}
|
||||
if (currentProjects.isNotEmpty) {
|
||||
parts.add('${currentProjects.length} 个项目');
|
||||
}
|
||||
if (teamMembers.isNotEmpty) {
|
||||
parts.add('${teamMembers.length} 位团队成员');
|
||||
}
|
||||
return parts.isEmpty ? '暂无信息' : parts.join(' · ');
|
||||
}
|
||||
}
|
||||
|
||||
class MemoryListResponse {
|
||||
final UserMemoryContent? userMemory;
|
||||
final WorkProfileContent? workMemory;
|
||||
|
||||
MemoryListResponse({this.userMemory, this.workMemory});
|
||||
|
||||
factory MemoryListResponse.fromJson(Map<String, dynamic> json) {
|
||||
return MemoryListResponse(
|
||||
userMemory: json['user_memory'] != null
|
||||
? UserMemoryContent.fromJson(
|
||||
json['user_memory'] as Map<String, dynamic>?,
|
||||
)
|
||||
: null,
|
||||
workMemory: json['work_memory'] != null
|
||||
? WorkProfileContent.fromJson(
|
||||
json['work_memory'] as Map<String, dynamic>?,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MemoryItemModel {
|
||||
final String id;
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
|
||||
MemoryItemModel({
|
||||
required this.id,
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
});
|
||||
}
|
||||
|
||||
class MockMemoryService {
|
||||
static final MockMemoryService _instance = MockMemoryService._internal();
|
||||
factory MockMemoryService() => _instance;
|
||||
|
||||
final List<MemoryItemModel> _items = [];
|
||||
|
||||
MockMemoryService._internal();
|
||||
|
||||
List<MemoryItemModel> get items => List.unmodifiable(_items);
|
||||
|
||||
List<MemoryItemModel> fetchMemoryItems() {
|
||||
return items;
|
||||
}
|
||||
}
|
||||
import 'package:social_app/core/api/i_api_client.dart';
|
||||
import '../models/memory_models.dart';
|
||||
|
||||
class MemoryService {
|
||||
final MockMemoryService _mock = MockMemoryService();
|
||||
final IApiClient _client;
|
||||
static const _prefix = '/api/v1/memories';
|
||||
|
||||
List<MemoryItemModel> getMemoryItems() {
|
||||
return _mock.fetchMemoryItems();
|
||||
MemoryService(this._client);
|
||||
|
||||
Future<MemoryListResponse> getAllMemories() async {
|
||||
final response = await _client.get<Map<String, dynamic>>(_prefix);
|
||||
return MemoryListResponse.fromJson(response.data!);
|
||||
}
|
||||
|
||||
Future<UserMemoryContent?> getUserMemory() async {
|
||||
final response = await _client.get<Map<String, dynamic>>('$_prefix/user');
|
||||
if (response.data == null) return null;
|
||||
return UserMemoryContent.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<WorkProfileContent?> getWorkMemory() async {
|
||||
final response = await _client.get<Map<String, dynamic>>('$_prefix/work');
|
||||
if (response.data == null) return null;
|
||||
return WorkProfileContent.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<UserMemoryContent> updateUserMemory(UserMemoryContent content) async {
|
||||
final response = await _client.put<Map<String, dynamic>>(
|
||||
'$_prefix/user',
|
||||
data: {'content': content.toJson()},
|
||||
);
|
||||
return UserMemoryContent.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<WorkProfileContent> updateWorkMemory(
|
||||
WorkProfileContent content,
|
||||
) async {
|
||||
final response = await _client.put<Map<String, dynamic>>(
|
||||
'$_prefix/work',
|
||||
data: {'content': content.toJson()},
|
||||
);
|
||||
return WorkProfileContent.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<UserMemoryContent> patchUserMemory(
|
||||
Map<String, dynamic> content,
|
||||
) async {
|
||||
final response = await _client.patch<Map<String, dynamic>>(
|
||||
'$_prefix/user',
|
||||
data: {'content': content},
|
||||
);
|
||||
return UserMemoryContent.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<WorkProfileContent> patchWorkMemory(
|
||||
Map<String, dynamic> content,
|
||||
) async {
|
||||
final response = await _client.patch<Map<String, dynamic>>(
|
||||
'$_prefix/work',
|
||||
data: {'content': content},
|
||||
);
|
||||
return WorkProfileContent.fromJson(response.data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_toggle_switch.dart';
|
||||
import '../../data/services/memory_service.dart';
|
||||
import 'package:social_app/core/di/injection.dart';
|
||||
import 'package:social_app/core/theme/design_tokens.dart';
|
||||
import 'package:social_app/core/router/app_routes.dart';
|
||||
import 'package:social_app/shared/widgets/app_loading_indicator.dart';
|
||||
import 'package:social_app/shared/widgets/app_pressable.dart';
|
||||
import 'package:social_app/shared/widgets/toast/toast.dart';
|
||||
import 'package:social_app/shared/widgets/toast/toast_type.dart';
|
||||
import '../widgets/settings_page_scaffold.dart';
|
||||
import '../../data/models/memory_models.dart';
|
||||
import '../../data/services/memory_service.dart';
|
||||
|
||||
class MemoryScreen extends StatefulWidget {
|
||||
const MemoryScreen({super.key});
|
||||
@@ -13,14 +19,38 @@ class MemoryScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MemoryScreenState extends State<MemoryScreen> {
|
||||
bool _memoryEnabled = true;
|
||||
final MemoryService _memoryService = MemoryService();
|
||||
late List<MemoryItemModel> _memoryItems;
|
||||
final MemoryService _memoryService = sl<MemoryService>();
|
||||
MemoryListResponse? _memoryData;
|
||||
bool _isLoading = true;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_memoryItems = _memoryService.getMemoryItems();
|
||||
_loadMemories();
|
||||
}
|
||||
|
||||
Future<void> _loadMemories() async {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final data = await _memoryService.getAllMemories();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_memoryData = data;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = '加载失败,请重试';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -28,18 +58,22 @@ class _MemoryScreenState extends State<MemoryScreen> {
|
||||
return SettingsPageScaffold(
|
||||
title: '我的记忆',
|
||||
onBack: () => context.pop(),
|
||||
footer: _buildFooter(),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildToggleCard(),
|
||||
if (_memoryItems.isNotEmpty) ...[
|
||||
const SizedBox(height: 14),
|
||||
_buildListTitle(),
|
||||
const SizedBox(height: 8),
|
||||
_buildMemoryList(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
if (_isLoading) ...[
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
_buildLoadingState(),
|
||||
] else if (_error != null) ...[
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
_buildErrorState(),
|
||||
] else ...[
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildMemoryCards(),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
_buildManageButton(),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -47,42 +81,122 @@ class _MemoryScreenState extends State<MemoryScreen> {
|
||||
|
||||
Widget _buildToggleCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.white, AppColors.surfaceInfoLight],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderTertiary),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.blue100.withValues(alpha: 0.35),
|
||||
blurRadius: 14,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'启用记忆',
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.blue100, AppColors.blue50],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.blue200.withValues(alpha: 0.45),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.auto_awesome,
|
||||
size: 22,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'智能记忆',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'持续学习你的偏好和习惯',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingState() {
|
||||
return Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: const AppLoadingIndicator(size: 32),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 48, color: AppColors.slate300),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text(
|
||||
_error ?? '加载失败',
|
||||
style: TextStyle(fontSize: 14, color: AppColors.slate500),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
AppPressable(
|
||||
onTap: _loadMemories,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.lg,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.blue100),
|
||||
),
|
||||
child: const Text(
|
||||
'重新加载',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
_buildToggle(_memoryEnabled, (v) {
|
||||
setState(() => _memoryEnabled = v);
|
||||
}),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'开启后,将持续记录并更新你的长期偏好',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: Color(0xFF71839F),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -90,122 +204,318 @@ class _MemoryScreenState extends State<MemoryScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildListTitle() {
|
||||
return const Text(
|
||||
'记忆条目',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate500,
|
||||
Widget _buildMemoryCards() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildSectionLabel('用户记忆'),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildUserMemoryCard(),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_buildSectionLabel('工作记忆'),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildWorkMemoryCard(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionLabel(String label) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMemoryList() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (int i = 0; i < _memoryItems.length; i++) ...[
|
||||
_buildMemoryItem(_memoryItems[i]),
|
||||
if (i < _memoryItems.length - 1) const SizedBox(height: 10),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
Widget _buildUserMemoryCard() {
|
||||
final userMemory = _memoryData?.userMemory;
|
||||
final hasData = userMemory != null;
|
||||
|
||||
Widget _buildMemoryItem(MemoryItemModel item) {
|
||||
return GestureDetector(
|
||||
onTap: () {},
|
||||
return AppPressable(
|
||||
onTap: () => context.push(AppRoutes.settingsMemoryUser),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
child: Container(
|
||||
height: 74,
|
||||
padding: const EdgeInsets.all(12),
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceTertiary,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.white, AppColors.surfaceInfoLight],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderTertiary),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.slate200.withValues(alpha: 0.45),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.blue100.withValues(alpha: 0.8),
|
||||
AppColors.blue50.withValues(alpha: 0.8),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person,
|
||||
size: 20,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'个人偏好',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
hasData ? userMemory.summary : '暂无信息',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right, size: 20, color: AppColors.slate400),
|
||||
],
|
||||
),
|
||||
if (hasData) ...[
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_buildMemoryStatsRow(
|
||||
icons: [
|
||||
Icons.people_outline,
|
||||
Icons.place_outlined,
|
||||
Icons.interests_outlined,
|
||||
Icons.schedule_outlined,
|
||||
],
|
||||
values: [
|
||||
'${userMemory.people.length}',
|
||||
'${userMemory.places.length}',
|
||||
'${userMemory.interests.length}',
|
||||
'${userMemory.recurringRoutines.length}',
|
||||
],
|
||||
labels: ['联系人', '地点', '兴趣', '日程'],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWorkMemoryCard() {
|
||||
final workMemory = _memoryData?.workMemory;
|
||||
final hasData = workMemory != null;
|
||||
|
||||
return AppPressable(
|
||||
onTap: () => context.push(AppRoutes.settingsMemoryWork),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.white, AppColors.surfaceTertiary],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.slate200.withValues(alpha: 0.4),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.violet500.withValues(alpha: 0.15),
|
||||
AppColors.violet500.withValues(alpha: 0.05),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.work_outline,
|
||||
size: 20,
|
||||
color: AppColors.violet600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'工作Profile',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
hasData ? workMemory.summary : '暂无信息',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right, size: 20, color: AppColors.slate400),
|
||||
],
|
||||
),
|
||||
if (hasData) ...[
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_buildMemoryStatsRow(
|
||||
icons: [
|
||||
Icons.psychology_outlined,
|
||||
Icons.build_outlined,
|
||||
Icons.folder_outlined,
|
||||
Icons.groups_outlined,
|
||||
],
|
||||
values: [
|
||||
'${workMemory.expertise.length}',
|
||||
'${workMemory.preferredTools.length}',
|
||||
'${workMemory.currentProjects.length}',
|
||||
'${workMemory.teamMembers.length}',
|
||||
],
|
||||
labels: ['专长', '工具', '项目', '团队'],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMemoryStatsRow({
|
||||
required List<IconData> icons,
|
||||
required List<String> values,
|
||||
required List<String> labels,
|
||||
}) {
|
||||
return Row(
|
||||
children: List.generate(icons.length, (index) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.sm),
|
||||
margin: EdgeInsets.only(
|
||||
right: index < icons.length - 1 ? AppSpacing.sm : 0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icons[index], size: 16, color: AppColors.slate400),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
values[index],
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
labels[index],
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget? _buildFooter() {
|
||||
return AppPressable(
|
||||
onTap: () {
|
||||
Toast.show(context, '记忆会随着你的使用自动完善', type: ToastType.info);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceInfoLight,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
border: Border.all(color: AppColors.borderQuaternary),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceInfo,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
Icon(Icons.info_outline, size: 16, color: AppColors.blue500),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
const Text(
|
||||
'点击卡片查看或编辑详情',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
child: Icon(item.icon, size: 16, color: AppColors.blue500),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
item.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
item.subtitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
size: 16,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildManageButton() {
|
||||
return GestureDetector(
|
||||
onTap: () {},
|
||||
child: Container(
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'管理记忆条目',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildToggle(bool value, ValueChanged<bool> onChanged) {
|
||||
return AppToggleSwitch(value: value, onChanged: onChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,942 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:social_app/core/di/injection.dart';
|
||||
import 'package:social_app/core/theme/design_tokens.dart';
|
||||
import 'package:social_app/shared/widgets/app_loading_indicator.dart';
|
||||
import 'package:social_app/shared/widgets/app_pressable.dart';
|
||||
import 'package:social_app/shared/widgets/toast/toast.dart';
|
||||
import 'package:social_app/shared/widgets/toast/toast_type.dart';
|
||||
import '../widgets/settings_page_scaffold.dart';
|
||||
import '../../data/models/memory_models.dart';
|
||||
import '../../data/services/memory_service.dart';
|
||||
|
||||
class UserMemoryDetailScreen extends StatefulWidget {
|
||||
const UserMemoryDetailScreen({super.key});
|
||||
|
||||
@override
|
||||
State<UserMemoryDetailScreen> createState() => _UserMemoryDetailScreenState();
|
||||
}
|
||||
|
||||
class _UserMemoryDetailScreenState extends State<UserMemoryDetailScreen> {
|
||||
final MemoryService _memoryService = sl<MemoryService>();
|
||||
UserMemoryContent? _memory;
|
||||
bool _isLoading = true;
|
||||
bool _isSaving = false;
|
||||
String? _error;
|
||||
bool _hasChanges = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadMemory();
|
||||
}
|
||||
|
||||
Future<void> _loadMemory() async {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final memory = await _memoryService.getUserMemory();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_memory = memory;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = '加载失败';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveMemory() async {
|
||||
if (_memory == null || !_hasChanges) return;
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isSaving = true;
|
||||
});
|
||||
|
||||
try {
|
||||
await _memoryService.updateUserMemory(_memory!);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isSaving = false;
|
||||
_hasChanges = false;
|
||||
});
|
||||
Toast.show(context, '保存成功', type: ToastType.success);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isSaving = false;
|
||||
});
|
||||
Toast.show(context, '保存失败', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateMemory(UserMemoryContent newMemory) {
|
||||
setState(() {
|
||||
_memory = newMemory;
|
||||
_hasChanges = true;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SettingsPageScaffold(
|
||||
title: '个人偏好',
|
||||
onBack: () => context.pop(),
|
||||
footer: _hasChanges ? _buildSaveButton() : null,
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (_isLoading) ...[
|
||||
const SizedBox(height: AppSpacing.xxl * 2),
|
||||
_buildLoadingState(),
|
||||
] else if (_error != null) ...[
|
||||
const SizedBox(height: AppSpacing.xxl * 2),
|
||||
_buildErrorState(),
|
||||
] else if (_memory != null) ...[
|
||||
_buildContent(),
|
||||
] else ...[
|
||||
const SizedBox(height: AppSpacing.xxl * 2),
|
||||
_buildEmptyState(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingState() {
|
||||
return const Center(child: AppLoadingIndicator(size: 32));
|
||||
}
|
||||
|
||||
Widget _buildErrorState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 48, color: AppColors.slate300),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text(_error ?? '加载失败', style: TextStyle(color: AppColors.slate500)),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
AppPressable(
|
||||
onTap: _loadMemory,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.lg,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.blue100),
|
||||
),
|
||||
child: const Text(
|
||||
'重新加载',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.person_off_outlined, size: 48, color: AppColors.slate300),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text('暂无个人偏好信息', style: TextStyle(color: AppColors.slate500)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSaveButton() {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: AppPressable(
|
||||
onTap: _isSaving ? null : _saveMemory,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
child: Container(
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [AppColors.blue500, AppColors.blue600],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x4D60A5FA),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: _isSaving
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
AppColors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'保存更改',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildBasicInfoSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildPeopleSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildPlacesSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildPreferencesSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildInterestsSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildAvoidTopicsSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildRecurringRoutinesSection(),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBasicInfoSection() {
|
||||
return _buildSection(
|
||||
title: '基本信息',
|
||||
icon: Icons.person_outline,
|
||||
children: [
|
||||
_buildEditField(
|
||||
label: '职业',
|
||||
value: _memory?.occupation,
|
||||
onChanged: (value) =>
|
||||
_updateMemory(_memory!.copyWith(occupation: value)),
|
||||
),
|
||||
_buildEditField(
|
||||
label: '时区',
|
||||
value: _memory?.timezone,
|
||||
onChanged: (value) =>
|
||||
_updateMemory(_memory!.copyWith(timezone: value)),
|
||||
),
|
||||
_buildEditField(
|
||||
label: '主要语言',
|
||||
value: _memory?.primaryLanguage,
|
||||
onChanged: (value) =>
|
||||
_updateMemory(_memory!.copyWith(primaryLanguage: value)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPeopleSection() {
|
||||
return _buildSection(
|
||||
title: '联系人',
|
||||
icon: Icons.people_outline,
|
||||
count: _memory?.people.length ?? 0,
|
||||
children: [
|
||||
if (_memory?.people.isEmpty ?? true)
|
||||
_buildEmptySection('暂无联系人')
|
||||
else
|
||||
..._memory!.people.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final person = entry.value;
|
||||
return _buildPersonItem(person, index);
|
||||
}),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildAddButton('添加联系人', () {
|
||||
final newPeople = List<Person>.from(_memory!.people)
|
||||
..add(Person(name: '新联系人'));
|
||||
_updateMemory(_memory!.copyWith(people: newPeople));
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPersonItem(Person person, int index) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '姓名',
|
||||
value: person.name,
|
||||
onChanged: (value) {
|
||||
final newPeople = List<Person>.from(_memory!.people);
|
||||
newPeople[index] = person.copyWith(name: value);
|
||||
_updateMemory(_memory!.copyWith(people: newPeople));
|
||||
},
|
||||
),
|
||||
),
|
||||
AppPressable(
|
||||
onTap: () {
|
||||
final newPeople = List<Person>.from(_memory!.people)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(people: newPeople));
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xs),
|
||||
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '关系',
|
||||
value: person.relationship,
|
||||
onChanged: (value) {
|
||||
final newPeople = List<Person>.from(_memory!.people);
|
||||
newPeople[index] = person.copyWith(relationship: value);
|
||||
_updateMemory(_memory!.copyWith(people: newPeople));
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '角色',
|
||||
value: person.role,
|
||||
onChanged: (value) {
|
||||
final newPeople = List<Person>.from(_memory!.people);
|
||||
newPeople[index] = person.copyWith(role: value);
|
||||
_updateMemory(_memory!.copyWith(people: newPeople));
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '联系方式',
|
||||
value: person.preferredContactChannel,
|
||||
onChanged: (value) {
|
||||
final newPeople = List<Person>.from(_memory!.people);
|
||||
newPeople[index] = person.copyWith(
|
||||
preferredContactChannel: value,
|
||||
);
|
||||
_updateMemory(_memory!.copyWith(people: newPeople));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '备注',
|
||||
value: person.notes,
|
||||
onChanged: (value) {
|
||||
final newPeople = List<Person>.from(_memory!.people);
|
||||
newPeople[index] = person.copyWith(notes: value);
|
||||
_updateMemory(_memory!.copyWith(people: newPeople));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlacesSection() {
|
||||
return _buildSection(
|
||||
title: '地点',
|
||||
icon: Icons.place_outlined,
|
||||
count: _memory?.places.length ?? 0,
|
||||
children: [
|
||||
if (_memory?.places.isEmpty ?? true)
|
||||
_buildEmptySection('暂无地点')
|
||||
else
|
||||
..._memory!.places.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final place = entry.value;
|
||||
return _buildPlaceItem(place, index);
|
||||
}),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildAddButton('添加地点', () {
|
||||
final newPlaces = List<Place>.from(_memory!.places)
|
||||
..add(Place(name: '新地点'));
|
||||
_updateMemory(_memory!.copyWith(places: newPlaces));
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlaceItem(Place place, int index) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '名称',
|
||||
value: place.name,
|
||||
onChanged: (value) {
|
||||
final newPlaces = List<Place>.from(_memory!.places);
|
||||
newPlaces[index] = place.copyWith(name: value);
|
||||
_updateMemory(_memory!.copyWith(places: newPlaces));
|
||||
},
|
||||
),
|
||||
),
|
||||
AppPressable(
|
||||
onTap: () {
|
||||
final newPlaces = List<Place>.from(_memory!.places)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(places: newPlaces));
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xs),
|
||||
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '类别',
|
||||
value: place.category,
|
||||
onChanged: (value) {
|
||||
final newPlaces = List<Place>.from(_memory!.places);
|
||||
newPlaces[index] = place.copyWith(category: value);
|
||||
_updateMemory(_memory!.copyWith(places: newPlaces));
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '偏好',
|
||||
value: place.preference,
|
||||
onChanged: (value) {
|
||||
final newPlaces = List<Place>.from(_memory!.places);
|
||||
newPlaces[index] = place.copyWith(preference: value);
|
||||
_updateMemory(_memory!.copyWith(places: newPlaces));
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '地址',
|
||||
value: place.address,
|
||||
onChanged: (value) {
|
||||
final newPlaces = List<Place>.from(_memory!.places);
|
||||
newPlaces[index] = place.copyWith(address: value);
|
||||
_updateMemory(_memory!.copyWith(places: newPlaces));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPreferencesSection() {
|
||||
final prefs = _memory!.preferences;
|
||||
return _buildSection(
|
||||
title: '偏好设置',
|
||||
icon: Icons.settings_outlined,
|
||||
children: [
|
||||
_buildEditField(
|
||||
label: '沟通风格',
|
||||
value: prefs.communicationStyle,
|
||||
onChanged: (value) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(
|
||||
preferences: prefs.copyWith(communicationStyle: value),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
_buildEditField(
|
||||
label: '位置偏好',
|
||||
value: prefs.locationPreference,
|
||||
onChanged: (value) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(
|
||||
preferences: prefs.copyWith(locationPreference: value),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
_buildEditField(
|
||||
label: '工作生活方式',
|
||||
value: prefs.workLifestyle,
|
||||
onChanged: (value) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(
|
||||
preferences: prefs.copyWith(workLifestyle: value),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInterestsSection() {
|
||||
return _buildSection(
|
||||
title: '兴趣',
|
||||
icon: Icons.interests_outlined,
|
||||
children: [
|
||||
_buildTagsSection(
|
||||
tags: _memory?.interests ?? [],
|
||||
onAdd: (tag) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(interests: [..._memory!.interests, tag]),
|
||||
);
|
||||
},
|
||||
onRemove: (index) {
|
||||
final newInterests = List<String>.from(_memory!.interests)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(interests: newInterests));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAvoidTopicsSection() {
|
||||
return _buildSection(
|
||||
title: '回避话题',
|
||||
icon: Icons.not_interested_outlined,
|
||||
children: [
|
||||
_buildTagsSection(
|
||||
tags: _memory?.avoidTopics ?? [],
|
||||
onAdd: (tag) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(avoidTopics: [..._memory!.avoidTopics, tag]),
|
||||
);
|
||||
},
|
||||
onRemove: (index) {
|
||||
final newTopics = List<String>.from(_memory!.avoidTopics)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(avoidTopics: newTopics));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRecurringRoutinesSection() {
|
||||
return _buildSection(
|
||||
title: '周期习惯',
|
||||
icon: Icons.schedule_outlined,
|
||||
count: _memory?.recurringRoutines.length ?? 0,
|
||||
children: [
|
||||
if (_memory?.recurringRoutines.isEmpty ?? true)
|
||||
_buildEmptySection('暂无周期习惯')
|
||||
else
|
||||
..._memory!.recurringRoutines.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final routine = entry.value;
|
||||
return _buildRoutineItem(routine, index);
|
||||
}),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildAddButton('添加习惯', () {
|
||||
final newRoutines = List<RecurringRoutine>.from(
|
||||
_memory!.recurringRoutines,
|
||||
)..add(RecurringRoutine(name: '新习惯'));
|
||||
_updateMemory(_memory!.copyWith(recurringRoutines: newRoutines));
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRoutineItem(RecurringRoutine routine, int index) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '名称',
|
||||
value: routine.name,
|
||||
onChanged: (value) {
|
||||
final newRoutines = List<RecurringRoutine>.from(
|
||||
_memory!.recurringRoutines,
|
||||
);
|
||||
newRoutines[index] = routine.copyWith(name: value);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(recurringRoutines: newRoutines),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
AppPressable(
|
||||
onTap: () {
|
||||
final newRoutines = List<RecurringRoutine>.from(
|
||||
_memory!.recurringRoutines,
|
||||
)..removeAt(index);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(recurringRoutines: newRoutines),
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xs),
|
||||
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '描述',
|
||||
value: routine.description,
|
||||
onChanged: (value) {
|
||||
final newRoutines = List<RecurringRoutine>.from(
|
||||
_memory!.recurringRoutines,
|
||||
);
|
||||
newRoutines[index] = routine.copyWith(description: value);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(recurringRoutines: newRoutines),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '周期',
|
||||
value: routine.cadence,
|
||||
onChanged: (value) {
|
||||
final newRoutines = List<RecurringRoutine>.from(
|
||||
_memory!.recurringRoutines,
|
||||
);
|
||||
newRoutines[index] = routine.copyWith(cadence: value);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(recurringRoutines: newRoutines),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSection({
|
||||
required String title,
|
||||
required IconData icon,
|
||||
int? count,
|
||||
required List<Widget> children,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: AppColors.blue500),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate800,
|
||||
),
|
||||
),
|
||||
if (count != null) ...[
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.sm,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
),
|
||||
child: Text(
|
||||
'$count',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
...children,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditField({
|
||||
required String label,
|
||||
String? value,
|
||||
required ValueChanged<String> onChanged,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: TextFormField(
|
||||
initialValue: value,
|
||||
onChanged: onChanged,
|
||||
style: const TextStyle(fontSize: 14, color: AppColors.slate800),
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
hintText: '输入$label',
|
||||
hintStyle: TextStyle(color: AppColors.slate400, fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptySection(String message) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
message,
|
||||
style: TextStyle(fontSize: 14, color: AppColors.slate400),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTagsSection({
|
||||
required List<String> tags,
|
||||
required ValueChanged<String> onAdd,
|
||||
required ValueChanged<int> onRemove,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
...tags.asMap().entries.map((entry) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
border: Border.all(color: AppColors.blue100),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
entry.value,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
AppPressable(
|
||||
onTap: () => onRemove(entry.key),
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
size: 14,
|
||||
color: AppColors.blue400,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
AppPressable(
|
||||
onTap: () => _showAddTagDialog(onAdd),
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
border: Border.all(
|
||||
color: AppColors.borderSecondary,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.add, size: 14, color: AppColors.slate500),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(
|
||||
'添加',
|
||||
style: TextStyle(fontSize: 13, color: AppColors.slate500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddTagDialog(ValueChanged<String> onAdd) {
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('添加'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(hintText: '输入内容'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (controller.text.isNotEmpty) {
|
||||
onAdd(controller.text);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('添加'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAddButton(String text, VoidCallback onTap) {
|
||||
return AppPressable(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(
|
||||
color: AppColors.borderSecondary,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.add, size: 18, color: AppColors.blue500),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,889 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:social_app/core/di/injection.dart';
|
||||
import 'package:social_app/core/theme/design_tokens.dart';
|
||||
import 'package:social_app/shared/widgets/app_loading_indicator.dart';
|
||||
import 'package:social_app/shared/widgets/app_pressable.dart';
|
||||
import 'package:social_app/shared/widgets/toast/toast.dart';
|
||||
import 'package:social_app/shared/widgets/toast/toast_type.dart';
|
||||
import '../widgets/settings_page_scaffold.dart';
|
||||
import '../../data/models/memory_models.dart';
|
||||
import '../../data/services/memory_service.dart';
|
||||
|
||||
class WorkMemoryDetailScreen extends StatefulWidget {
|
||||
const WorkMemoryDetailScreen({super.key});
|
||||
|
||||
@override
|
||||
State<WorkMemoryDetailScreen> createState() => _WorkMemoryDetailScreenState();
|
||||
}
|
||||
|
||||
class _WorkMemoryDetailScreenState extends State<WorkMemoryDetailScreen> {
|
||||
final MemoryService _memoryService = sl<MemoryService>();
|
||||
WorkProfileContent? _memory;
|
||||
bool _isLoading = true;
|
||||
bool _isSaving = false;
|
||||
String? _error;
|
||||
bool _hasChanges = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadMemory();
|
||||
}
|
||||
|
||||
Future<void> _loadMemory() async {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final memory = await _memoryService.getWorkMemory();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_memory = memory;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = '加载失败';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveMemory() async {
|
||||
if (_memory == null || !_hasChanges) return;
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isSaving = true;
|
||||
});
|
||||
|
||||
try {
|
||||
await _memoryService.updateWorkMemory(_memory!);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isSaving = false;
|
||||
_hasChanges = false;
|
||||
});
|
||||
Toast.show(context, '保存成功', type: ToastType.success);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isSaving = false;
|
||||
});
|
||||
Toast.show(context, '保存失败', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateMemory(WorkProfileContent newMemory) {
|
||||
setState(() {
|
||||
_memory = newMemory;
|
||||
_hasChanges = true;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SettingsPageScaffold(
|
||||
title: '工作Profile',
|
||||
onBack: () => context.pop(),
|
||||
footer: _hasChanges ? _buildSaveButton() : null,
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (_isLoading) ...[
|
||||
const SizedBox(height: AppSpacing.xxl * 2),
|
||||
_buildLoadingState(),
|
||||
] else if (_error != null) ...[
|
||||
const SizedBox(height: AppSpacing.xxl * 2),
|
||||
_buildErrorState(),
|
||||
] else if (_memory != null) ...[
|
||||
_buildContent(),
|
||||
] else ...[
|
||||
const SizedBox(height: AppSpacing.xxl * 2),
|
||||
_buildEmptyState(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingState() {
|
||||
return const Center(child: AppLoadingIndicator(size: 32));
|
||||
}
|
||||
|
||||
Widget _buildErrorState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 48, color: AppColors.slate300),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text(_error ?? '加载失败', style: TextStyle(color: AppColors.slate500)),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
AppPressable(
|
||||
onTap: _loadMemory,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.lg,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.blue100),
|
||||
),
|
||||
child: const Text(
|
||||
'重新加载',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.work_off_outlined, size: 48, color: AppColors.slate300),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text('暂无工作信息', style: TextStyle(color: AppColors.slate500)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSaveButton() {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: AppPressable(
|
||||
onTap: _isSaving ? null : _saveMemory,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
child: Container(
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [AppColors.blue500, AppColors.blue600],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x4D60A5FA),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: _isSaving
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
AppColors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'保存更改',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildBasicInfoSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildExpertiseSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildPreferredToolsSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildProjectsSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildTeamMembersSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildWorkHabitsSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildTeamContextSection(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildWorkRulesSection(),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBasicInfoSection() {
|
||||
return _buildSection(
|
||||
title: '基本信息',
|
||||
icon: Icons.work_outline,
|
||||
children: [
|
||||
_buildEditField(
|
||||
label: '职业',
|
||||
value: _memory?.occupation,
|
||||
onChanged: (value) =>
|
||||
_updateMemory(_memory!.copyWith(occupation: value)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExpertiseSection() {
|
||||
return _buildSection(
|
||||
title: '专长',
|
||||
icon: Icons.psychology_outlined,
|
||||
count: _memory?.expertise.length ?? 0,
|
||||
children: [
|
||||
_buildTagsSection(
|
||||
tags: _memory?.expertise ?? [],
|
||||
onAdd: (tag) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(expertise: [..._memory!.expertise, tag]),
|
||||
);
|
||||
},
|
||||
onRemove: (index) {
|
||||
final newExpertise = List<String>.from(_memory!.expertise)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(expertise: newExpertise));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPreferredToolsSection() {
|
||||
return _buildSection(
|
||||
title: '偏好工具',
|
||||
icon: Icons.build_outlined,
|
||||
count: _memory?.preferredTools.length ?? 0,
|
||||
children: [
|
||||
_buildTagsSection(
|
||||
tags: _memory?.preferredTools ?? [],
|
||||
onAdd: (tag) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(
|
||||
preferredTools: [..._memory!.preferredTools, tag],
|
||||
),
|
||||
);
|
||||
},
|
||||
onRemove: (index) {
|
||||
final newTools = List<String>.from(_memory!.preferredTools)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(preferredTools: newTools));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProjectsSection() {
|
||||
return _buildSection(
|
||||
title: '当前项目',
|
||||
icon: Icons.folder_outlined,
|
||||
count: _memory?.currentProjects.length ?? 0,
|
||||
children: [
|
||||
if (_memory?.currentProjects.isEmpty ?? true)
|
||||
_buildEmptySection('暂无项目')
|
||||
else
|
||||
..._memory!.currentProjects.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final project = entry.value;
|
||||
return _buildProjectItem(project, index);
|
||||
}),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildAddButton('添加项目', () {
|
||||
final newProjects = List<CurrentProject>.from(
|
||||
_memory!.currentProjects,
|
||||
)..add(CurrentProject(name: '新项目'));
|
||||
_updateMemory(_memory!.copyWith(currentProjects: newProjects));
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProjectItem(CurrentProject project, int index) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '项目名称',
|
||||
value: project.name,
|
||||
onChanged: (value) {
|
||||
final newProjects = List<CurrentProject>.from(
|
||||
_memory!.currentProjects,
|
||||
);
|
||||
newProjects[index] = project.copyWith(name: value);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(currentProjects: newProjects),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
AppPressable(
|
||||
onTap: () {
|
||||
final newProjects = List<CurrentProject>.from(
|
||||
_memory!.currentProjects,
|
||||
)..removeAt(index);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(currentProjects: newProjects),
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xs),
|
||||
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '状态',
|
||||
value: project.status,
|
||||
onChanged: (value) {
|
||||
final newProjects = List<CurrentProject>.from(
|
||||
_memory!.currentProjects,
|
||||
);
|
||||
newProjects[index] = project.copyWith(status: value);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(currentProjects: newProjects),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '优先级',
|
||||
value: project.priority,
|
||||
onChanged: (value) {
|
||||
final newProjects = List<CurrentProject>.from(
|
||||
_memory!.currentProjects,
|
||||
);
|
||||
newProjects[index] = project.copyWith(priority: value);
|
||||
_updateMemory(
|
||||
_memory!.copyWith(currentProjects: newProjects),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '描述',
|
||||
value: project.description,
|
||||
onChanged: (value) {
|
||||
final newProjects = List<CurrentProject>.from(
|
||||
_memory!.currentProjects,
|
||||
);
|
||||
newProjects[index] = project.copyWith(description: value);
|
||||
_updateMemory(_memory!.copyWith(currentProjects: newProjects));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '截止日期',
|
||||
value: project.deadline?.toIso8601String().split('T').first,
|
||||
onChanged: (value) {
|
||||
final newProjects = List<CurrentProject>.from(
|
||||
_memory!.currentProjects,
|
||||
);
|
||||
newProjects[index] = project.copyWith(
|
||||
deadline: value.isNotEmpty ? DateTime.tryParse(value) : null,
|
||||
);
|
||||
_updateMemory(_memory!.copyWith(currentProjects: newProjects));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTeamMembersSection() {
|
||||
return _buildSection(
|
||||
title: '团队成员',
|
||||
icon: Icons.groups_outlined,
|
||||
count: _memory?.teamMembers.length ?? 0,
|
||||
children: [
|
||||
if (_memory?.teamMembers.isEmpty ?? true)
|
||||
_buildEmptySection('暂无团队成员')
|
||||
else
|
||||
..._memory!.teamMembers.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final member = entry.value;
|
||||
return _buildTeamMemberItem(member, index);
|
||||
}),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildAddButton('添加成员', () {
|
||||
final newMembers = List<TeamMember>.from(_memory!.teamMembers)
|
||||
..add(TeamMember(name: '新成员'));
|
||||
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTeamMemberItem(TeamMember member, int index) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '姓名',
|
||||
value: member.name,
|
||||
onChanged: (value) {
|
||||
final newMembers = List<TeamMember>.from(
|
||||
_memory!.teamMembers,
|
||||
);
|
||||
newMembers[index] = member.copyWith(name: value);
|
||||
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
|
||||
},
|
||||
),
|
||||
),
|
||||
AppPressable(
|
||||
onTap: () {
|
||||
final newMembers = List<TeamMember>.from(_memory!.teamMembers)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xs),
|
||||
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '角色',
|
||||
value: member.role,
|
||||
onChanged: (value) {
|
||||
final newMembers = List<TeamMember>.from(
|
||||
_memory!.teamMembers,
|
||||
);
|
||||
newMembers[index] = member.copyWith(role: value);
|
||||
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: _buildEditField(
|
||||
label: '关系',
|
||||
value: member.relationship,
|
||||
onChanged: (value) {
|
||||
final newMembers = List<TeamMember>.from(
|
||||
_memory!.teamMembers,
|
||||
);
|
||||
newMembers[index] = member.copyWith(relationship: value);
|
||||
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '联系方式',
|
||||
value: member.preferredContactChannel,
|
||||
onChanged: (value) {
|
||||
final newMembers = List<TeamMember>.from(_memory!.teamMembers);
|
||||
newMembers[index] = member.copyWith(
|
||||
preferredContactChannel: value,
|
||||
);
|
||||
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '备注',
|
||||
value: member.notes,
|
||||
onChanged: (value) {
|
||||
final newMembers = List<TeamMember>.from(_memory!.teamMembers);
|
||||
newMembers[index] = member.copyWith(notes: value);
|
||||
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWorkHabitsSection() {
|
||||
final habits = _memory!.workHabits;
|
||||
return _buildSection(
|
||||
title: '工作习惯',
|
||||
icon: Icons.schedule_outlined,
|
||||
children: [
|
||||
_buildEditField(
|
||||
label: '通知渠道',
|
||||
value: habits.notificationChannel,
|
||||
onChanged: (value) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(
|
||||
workHabits: habits.copyWith(notificationChannel: value),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildEditField(
|
||||
label: '备注',
|
||||
value: habits.notes,
|
||||
onChanged: (value) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(workHabits: habits.copyWith(notes: value)),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTeamContextSection() {
|
||||
return _buildSection(
|
||||
title: '团队背景',
|
||||
icon: Icons.business_outlined,
|
||||
children: [
|
||||
_buildEditField(
|
||||
label: '团队背景描述',
|
||||
value: _memory?.teamContext,
|
||||
onChanged: (value) =>
|
||||
_updateMemory(_memory!.copyWith(teamContext: value)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWorkRulesSection() {
|
||||
return _buildSection(
|
||||
title: '工作规则',
|
||||
icon: Icons.rule_outlined,
|
||||
children: [
|
||||
_buildTagsSection(
|
||||
tags: _memory?.workRules ?? [],
|
||||
onAdd: (tag) {
|
||||
_updateMemory(
|
||||
_memory!.copyWith(workRules: [..._memory!.workRules, tag]),
|
||||
);
|
||||
},
|
||||
onRemove: (index) {
|
||||
final newRules = List<String>.from(_memory!.workRules)
|
||||
..removeAt(index);
|
||||
_updateMemory(_memory!.copyWith(workRules: newRules));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSection({
|
||||
required String title,
|
||||
required IconData icon,
|
||||
int? count,
|
||||
required List<Widget> children,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: AppColors.violet500),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate800,
|
||||
),
|
||||
),
|
||||
if (count != null) ...[
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.sm,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.violet500.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
),
|
||||
child: Text(
|
||||
'$count',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.violet600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
...children,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditField({
|
||||
required String label,
|
||||
String? value,
|
||||
required ValueChanged<String> onChanged,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: TextFormField(
|
||||
initialValue: value,
|
||||
onChanged: onChanged,
|
||||
style: const TextStyle(fontSize: 14, color: AppColors.slate800),
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
hintText: '输入$label',
|
||||
hintStyle: TextStyle(color: AppColors.slate400, fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptySection(String message) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
message,
|
||||
style: TextStyle(fontSize: 14, color: AppColors.slate400),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTagsSection({
|
||||
required List<String> tags,
|
||||
required ValueChanged<String> onAdd,
|
||||
required ValueChanged<int> onRemove,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
...tags.asMap().entries.map((entry) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.violet500.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
border: Border.all(
|
||||
color: AppColors.violet500.withValues(alpha: 0.3),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
entry.value,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.violet600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
AppPressable(
|
||||
onTap: () => onRemove(entry.key),
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
size: 14,
|
||||
color: AppColors.violet500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
AppPressable(
|
||||
onTap: () => _showAddTagDialog(onAdd),
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
border: Border.all(
|
||||
color: AppColors.borderSecondary,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.add, size: 14, color: AppColors.slate500),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(
|
||||
'添加',
|
||||
style: TextStyle(fontSize: 13, color: AppColors.slate500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddTagDialog(ValueChanged<String> onAdd) {
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('添加'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(hintText: '输入内容'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (controller.text.isNotEmpty) {
|
||||
onAdd(controller.text);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('添加'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAddButton(String text, VoidCallback onTap) {
|
||||
return AppPressable(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceSecondary,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(
|
||||
color: AppColors.borderSecondary,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.add, size: 18, color: AppColors.violet500),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.violet600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user