Add ideas and reminders CRUD flows with navigation
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
enum IdeaType { gift, event }
|
||||
|
||||
enum ReminderCadence { daily, weekly, monthly }
|
||||
|
||||
@immutable
|
||||
class PersonProfile {
|
||||
const PersonProfile({
|
||||
@@ -61,10 +65,10 @@ class PersonProfile {
|
||||
relationship: json['relationship'] as String,
|
||||
affinityScore: (json['affinityScore'] as num).toInt(),
|
||||
nextMoment: DateTime.parse(json['nextMoment'] as String).toLocal(),
|
||||
tags: (json['tags'] as List<dynamic>)
|
||||
tags: (json['tags'] as List<dynamic>? ?? <dynamic>[])
|
||||
.map((dynamic tag) => '$tag')
|
||||
.toList(),
|
||||
notes: json['notes'] as String,
|
||||
.toList(growable: false),
|
||||
notes: json['notes'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -128,6 +132,139 @@ class RelationshipMoment {
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class RelationshipIdea {
|
||||
const RelationshipIdea({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.details,
|
||||
required this.createdAt,
|
||||
this.personId,
|
||||
this.isArchived = false,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String? personId;
|
||||
final IdeaType type;
|
||||
final String title;
|
||||
final String details;
|
||||
final DateTime createdAt;
|
||||
final bool isArchived;
|
||||
|
||||
RelationshipIdea copyWith({
|
||||
String? id,
|
||||
String? personId,
|
||||
IdeaType? type,
|
||||
String? title,
|
||||
String? details,
|
||||
DateTime? createdAt,
|
||||
bool? isArchived,
|
||||
}) {
|
||||
return RelationshipIdea(
|
||||
id: id ?? this.id,
|
||||
personId: personId ?? this.personId,
|
||||
type: type ?? this.type,
|
||||
title: title ?? this.title,
|
||||
details: details ?? this.details,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
isArchived: isArchived ?? this.isArchived,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'personId': personId,
|
||||
'type': type.name,
|
||||
'title': title,
|
||||
'details': details,
|
||||
'createdAt': createdAt.toUtc().toIso8601String(),
|
||||
'isArchived': isArchived,
|
||||
};
|
||||
}
|
||||
|
||||
factory RelationshipIdea.fromJson(Map<String, dynamic> json) {
|
||||
final String typeName = json['type'] as String? ?? IdeaType.gift.name;
|
||||
return RelationshipIdea(
|
||||
id: json['id'] as String,
|
||||
personId: json['personId'] as String?,
|
||||
type: IdeaType.values.firstWhere(
|
||||
(IdeaType type) => type.name == typeName,
|
||||
orElse: () => IdeaType.gift,
|
||||
),
|
||||
title: json['title'] as String,
|
||||
details: json['details'] as String? ?? '',
|
||||
createdAt: DateTime.parse(json['createdAt'] as String).toLocal(),
|
||||
isArchived: json['isArchived'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class ReminderRule {
|
||||
const ReminderRule({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.cadence,
|
||||
required this.nextAt,
|
||||
this.personId,
|
||||
this.enabled = true,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String? personId;
|
||||
final String title;
|
||||
final ReminderCadence cadence;
|
||||
final DateTime nextAt;
|
||||
final bool enabled;
|
||||
|
||||
ReminderRule copyWith({
|
||||
String? id,
|
||||
String? personId,
|
||||
String? title,
|
||||
ReminderCadence? cadence,
|
||||
DateTime? nextAt,
|
||||
bool? enabled,
|
||||
}) {
|
||||
return ReminderRule(
|
||||
id: id ?? this.id,
|
||||
personId: personId ?? this.personId,
|
||||
title: title ?? this.title,
|
||||
cadence: cadence ?? this.cadence,
|
||||
nextAt: nextAt ?? this.nextAt,
|
||||
enabled: enabled ?? this.enabled,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'personId': personId,
|
||||
'title': title,
|
||||
'cadence': cadence.name,
|
||||
'nextAt': nextAt.toUtc().toIso8601String(),
|
||||
'enabled': enabled,
|
||||
};
|
||||
}
|
||||
|
||||
factory ReminderRule.fromJson(Map<String, dynamic> json) {
|
||||
final String cadenceName =
|
||||
json['cadence'] as String? ?? ReminderCadence.weekly.name;
|
||||
return ReminderRule(
|
||||
id: json['id'] as String,
|
||||
personId: json['personId'] as String?,
|
||||
title: json['title'] as String,
|
||||
cadence: ReminderCadence.values.firstWhere(
|
||||
(ReminderCadence cadence) => cadence.name == cadenceName,
|
||||
orElse: () => ReminderCadence.weekly,
|
||||
),
|
||||
nextAt: DateTime.parse(json['nextAt'] as String).toLocal(),
|
||||
enabled: json['enabled'] as bool? ?? true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class DashboardTask {
|
||||
const DashboardTask({
|
||||
@@ -201,21 +338,29 @@ class LocalDataState {
|
||||
const LocalDataState({
|
||||
required this.people,
|
||||
required this.moments,
|
||||
required this.ideas,
|
||||
required this.reminders,
|
||||
required this.tasks,
|
||||
});
|
||||
|
||||
final List<PersonProfile> people;
|
||||
final List<RelationshipMoment> moments;
|
||||
final List<RelationshipIdea> ideas;
|
||||
final List<ReminderRule> reminders;
|
||||
final List<DashboardTask> tasks;
|
||||
|
||||
LocalDataState copyWith({
|
||||
List<PersonProfile>? people,
|
||||
List<RelationshipMoment>? moments,
|
||||
List<RelationshipIdea>? ideas,
|
||||
List<ReminderRule>? reminders,
|
||||
List<DashboardTask>? tasks,
|
||||
}) {
|
||||
return LocalDataState(
|
||||
people: people ?? this.people,
|
||||
moments: moments ?? this.moments,
|
||||
ideas: ideas ?? this.ideas,
|
||||
reminders: reminders ?? this.reminders,
|
||||
tasks: tasks ?? this.tasks,
|
||||
);
|
||||
}
|
||||
@@ -227,11 +372,9 @@ class LocalDataState {
|
||||
upcomingPlans: people
|
||||
.where((PersonProfile p) => p.nextMoment.isAfter(baseline))
|
||||
.length,
|
||||
pendingIdeas: people.fold<int>(
|
||||
0,
|
||||
(int acc, PersonProfile person) =>
|
||||
acc + (person.tags.isNotEmpty ? 1 : 0),
|
||||
),
|
||||
pendingIdeas: ideas
|
||||
.where((RelationshipIdea idea) => !idea.isArchived)
|
||||
.length,
|
||||
weeklyConsistency: moments.isEmpty
|
||||
? 0
|
||||
: (70 + moments.length * 4).clamp(0, 100),
|
||||
@@ -246,6 +389,12 @@ class LocalDataState {
|
||||
'moments': moments
|
||||
.map((RelationshipMoment moment) => moment.toJson())
|
||||
.toList(growable: false),
|
||||
'ideas': ideas
|
||||
.map((RelationshipIdea idea) => idea.toJson())
|
||||
.toList(growable: false),
|
||||
'reminders': reminders
|
||||
.map((ReminderRule reminder) => reminder.toJson())
|
||||
.toList(growable: false),
|
||||
'tasks': tasks
|
||||
.map((DashboardTask task) => task.toJson())
|
||||
.toList(growable: false),
|
||||
@@ -254,19 +403,31 @@ class LocalDataState {
|
||||
|
||||
factory LocalDataState.fromJson(Map<String, dynamic> json) {
|
||||
return LocalDataState(
|
||||
people: (json['people'] as List<dynamic>)
|
||||
people: (json['people'] as List<dynamic>? ?? <dynamic>[])
|
||||
.map(
|
||||
(dynamic person) =>
|
||||
PersonProfile.fromJson(person as Map<String, dynamic>),
|
||||
)
|
||||
.toList(growable: false),
|
||||
moments: (json['moments'] as List<dynamic>)
|
||||
moments: (json['moments'] as List<dynamic>? ?? <dynamic>[])
|
||||
.map(
|
||||
(dynamic moment) =>
|
||||
RelationshipMoment.fromJson(moment as Map<String, dynamic>),
|
||||
)
|
||||
.toList(growable: false),
|
||||
tasks: (json['tasks'] as List<dynamic>)
|
||||
ideas: (json['ideas'] as List<dynamic>? ?? <dynamic>[])
|
||||
.map(
|
||||
(dynamic idea) =>
|
||||
RelationshipIdea.fromJson(idea as Map<String, dynamic>),
|
||||
)
|
||||
.toList(growable: false),
|
||||
reminders: (json['reminders'] as List<dynamic>? ?? <dynamic>[])
|
||||
.map(
|
||||
(dynamic reminder) =>
|
||||
ReminderRule.fromJson(reminder as Map<String, dynamic>),
|
||||
)
|
||||
.toList(growable: false),
|
||||
tasks: (json['tasks'] as List<dynamic>? ?? <dynamic>[])
|
||||
.map(
|
||||
(dynamic task) =>
|
||||
DashboardTask.fromJson(task as Map<String, dynamic>),
|
||||
@@ -332,6 +493,40 @@ class LocalDataState {
|
||||
type: 'gift',
|
||||
),
|
||||
],
|
||||
ideas: <RelationshipIdea>[
|
||||
RelationshipIdea(
|
||||
id: 'i-1',
|
||||
personId: 'p-ava',
|
||||
type: IdeaType.gift,
|
||||
title: 'Handwritten recipe journal',
|
||||
details: 'Collect 10 memories and recipes from this year.',
|
||||
createdAt: DateTime(2026, 2, 12, 9),
|
||||
),
|
||||
RelationshipIdea(
|
||||
id: 'i-2',
|
||||
personId: 'p-mila',
|
||||
type: IdeaType.event,
|
||||
title: 'Plant market + brunch date',
|
||||
details: 'Saturday morning slot; book nearby cafe in advance.',
|
||||
createdAt: DateTime(2026, 2, 13, 11),
|
||||
),
|
||||
],
|
||||
reminders: <ReminderRule>[
|
||||
ReminderRule(
|
||||
id: 'r-1',
|
||||
personId: 'p-jordan',
|
||||
title: 'Weekly check-in message',
|
||||
cadence: ReminderCadence.weekly,
|
||||
nextAt: DateTime(2026, 2, 18, 18),
|
||||
),
|
||||
ReminderRule(
|
||||
id: 'r-2',
|
||||
personId: 'p-ava',
|
||||
title: 'Sunday ritual planning',
|
||||
cadence: ReminderCadence.weekly,
|
||||
nextAt: DateTime(2026, 2, 16, 10),
|
||||
),
|
||||
],
|
||||
tasks: <DashboardTask>[
|
||||
DashboardTask(
|
||||
id: 't-1',
|
||||
|
||||
Reference in New Issue
Block a user