1167 lines
36 KiB
Dart
1167 lines
36 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:relationship_saver/core/config/app_theme.dart';
|
|
import 'package:relationship_saver/features/local/local_models.dart';
|
|
import 'package:relationship_saver/features/local/local_repository.dart';
|
|
import 'package:relationship_saver/features/shared/frosted_card.dart';
|
|
|
|
class SelectedPersonIdNotifier extends Notifier<String?> {
|
|
@override
|
|
String? build() => null;
|
|
|
|
void select(String id) {
|
|
state = id;
|
|
}
|
|
|
|
void clear() {
|
|
state = null;
|
|
}
|
|
}
|
|
|
|
final NotifierProvider<SelectedPersonIdNotifier, String?>
|
|
selectedPersonIdProvider = NotifierProvider<SelectedPersonIdNotifier, String?>(
|
|
SelectedPersonIdNotifier.new,
|
|
);
|
|
|
|
enum _PersonQuickAction { capture, note, idea, reminder }
|
|
|
|
class PeopleView extends ConsumerWidget {
|
|
const PeopleView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final AsyncValue<LocalDataState> localData = ref.watch(
|
|
localRepositoryProvider,
|
|
);
|
|
|
|
return localData.when(
|
|
data: (LocalDataState data) {
|
|
final List<PersonProfile> people = data.people;
|
|
if (people.isEmpty) {
|
|
return _EmptyPeopleView(onAdd: () => _handleAddPerson(context, ref));
|
|
}
|
|
|
|
final String selectedId =
|
|
ref.watch(selectedPersonIdProvider) ?? people.first.id;
|
|
final PersonProfile selected = people.firstWhere(
|
|
(PersonProfile person) => person.id == selectedId,
|
|
orElse: () => people.first,
|
|
);
|
|
|
|
return LayoutBuilder(
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
|
final bool isCompact = constraints.maxWidth < 860;
|
|
if (isCompact) {
|
|
return _buildCompactLayout(context, ref, people, selected);
|
|
}
|
|
return _buildWideLayout(context, ref, people, selected);
|
|
},
|
|
);
|
|
},
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (Object error, StackTrace stackTrace) {
|
|
return const Center(child: Text('Unable to load people'));
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> _handleAddPerson(BuildContext context, WidgetRef ref) async {
|
|
final _PersonDraft? draft = await showDialog<_PersonDraft>(
|
|
context: context,
|
|
builder: (BuildContext context) =>
|
|
const _PersonEditorDialog(title: 'Add Person'),
|
|
);
|
|
|
|
if (draft == null) {
|
|
return;
|
|
}
|
|
|
|
await ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.addPerson(
|
|
name: draft.name,
|
|
relationship: draft.relationship,
|
|
notes: draft.notes,
|
|
tags: draft.tags,
|
|
location: draft.location,
|
|
);
|
|
}
|
|
|
|
Future<void> _handleEditPerson(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
PersonProfile person,
|
|
) async {
|
|
final _PersonDraft? draft = await showDialog<_PersonDraft>(
|
|
context: context,
|
|
builder: (BuildContext context) => _PersonEditorDialog(
|
|
title: 'Edit Person',
|
|
initial: _PersonDraft(
|
|
name: person.name,
|
|
relationship: person.relationship,
|
|
notes: person.notes,
|
|
tags: person.tags,
|
|
location: person.location,
|
|
),
|
|
),
|
|
);
|
|
|
|
if (draft == null) {
|
|
return;
|
|
}
|
|
|
|
await ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.updatePerson(
|
|
person.copyWith(
|
|
name: draft.name,
|
|
relationship: draft.relationship,
|
|
notes: draft.notes,
|
|
tags: draft.tags,
|
|
location: draft.location,
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _handleDeletePerson(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
String personId,
|
|
) async {
|
|
final bool? confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: const Text('Delete person?'),
|
|
content: const Text(
|
|
'This will remove the person and related moments from local storage.',
|
|
),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
child: const Text('Delete'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
|
|
if (confirmed != true) {
|
|
return;
|
|
}
|
|
|
|
await ref.read(localRepositoryProvider.notifier).deletePerson(personId);
|
|
ref.read(selectedPersonIdProvider.notifier).clear();
|
|
}
|
|
|
|
Widget _buildWideLayout(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
List<PersonProfile> people,
|
|
PersonProfile selected,
|
|
) {
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(28, 24, 28, 28),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
flex: 5,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
_PeopleHeader(
|
|
onAdd: () => _handleAddPerson(context, ref),
|
|
compact: false,
|
|
),
|
|
const SizedBox(height: 20),
|
|
Expanded(
|
|
child: ListView.separated(
|
|
itemCount: people.length,
|
|
separatorBuilder: (_, _) => const SizedBox(height: 12),
|
|
itemBuilder: (BuildContext context, int index) {
|
|
final PersonProfile person = people[index];
|
|
return _PersonListItem(
|
|
person: person,
|
|
selectedId: selected.id,
|
|
onSelect: () {
|
|
ref
|
|
.read(selectedPersonIdProvider.notifier)
|
|
.select(person.id);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 18),
|
|
Expanded(
|
|
flex: 6,
|
|
child: FrostedCard(
|
|
child: _PersonDetail(
|
|
person: selected,
|
|
onEdit: () => _handleEditPerson(context, ref, selected),
|
|
onDelete: () => _handleDeletePerson(context, ref, selected.id),
|
|
onQuickAction: (_PersonQuickAction action) =>
|
|
_handleQuickAction(context, ref, selected, action),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCompactLayout(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
List<PersonProfile> people,
|
|
PersonProfile selected,
|
|
) {
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(18, 16, 18, 20),
|
|
child: ListView(
|
|
children: <Widget>[
|
|
_PeopleHeader(
|
|
onAdd: () => _handleAddPerson(context, ref),
|
|
compact: true,
|
|
),
|
|
const SizedBox(height: 14),
|
|
...people.map(
|
|
(PersonProfile person) => Padding(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: _PersonListItem(
|
|
person: person,
|
|
selectedId: selected.id,
|
|
onSelect: () {
|
|
ref.read(selectedPersonIdProvider.notifier).select(person.id);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
FrostedCard(
|
|
child: _PersonDetail(
|
|
person: selected,
|
|
compact: true,
|
|
onEdit: () => _handleEditPerson(context, ref, selected),
|
|
onDelete: () => _handleDeletePerson(context, ref, selected.id),
|
|
onQuickAction: (_PersonQuickAction action) =>
|
|
_handleQuickAction(context, ref, selected, action),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _handleQuickAction(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
PersonProfile person,
|
|
_PersonQuickAction action,
|
|
) async {
|
|
switch (action) {
|
|
case _PersonQuickAction.capture:
|
|
final String? summary = await _showQuickTextCaptureDialog(
|
|
context,
|
|
title: 'Add Capture',
|
|
hintText: 'What happened in this interaction?',
|
|
);
|
|
if (summary == null) {
|
|
return;
|
|
}
|
|
await ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.addMoment(personId: person.id, summary: summary, type: 'capture');
|
|
return;
|
|
case _PersonQuickAction.note:
|
|
final String? note = await _showQuickTextCaptureDialog(
|
|
context,
|
|
title: 'Add Note',
|
|
hintText: 'Write a quick context note...',
|
|
);
|
|
if (note == null) {
|
|
return;
|
|
}
|
|
await ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.addMoment(personId: person.id, summary: note, type: 'note');
|
|
return;
|
|
case _PersonQuickAction.idea:
|
|
final _QuickIdeaDraft? idea = await showDialog<_QuickIdeaDraft>(
|
|
context: context,
|
|
builder: (BuildContext context) => const _QuickIdeaDialog(),
|
|
);
|
|
if (idea == null) {
|
|
return;
|
|
}
|
|
await ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.addIdea(
|
|
type: idea.type,
|
|
title: idea.title,
|
|
details: idea.details,
|
|
personId: person.id,
|
|
);
|
|
return;
|
|
case _PersonQuickAction.reminder:
|
|
final _QuickReminderDraft? reminder =
|
|
await showDialog<_QuickReminderDraft>(
|
|
context: context,
|
|
builder: (BuildContext context) => const _QuickReminderDialog(),
|
|
);
|
|
if (reminder == null) {
|
|
return;
|
|
}
|
|
await ref
|
|
.read(localRepositoryProvider.notifier)
|
|
.addReminder(
|
|
title: reminder.title,
|
|
cadence: reminder.cadence,
|
|
nextAt: reminder.nextAt,
|
|
personId: person.id,
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
Future<String?> _showQuickTextCaptureDialog(
|
|
BuildContext context, {
|
|
required String title,
|
|
required String hintText,
|
|
}) async {
|
|
final TextEditingController controller = TextEditingController();
|
|
final String? result = await showDialog<String>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(title),
|
|
content: TextField(
|
|
controller: controller,
|
|
minLines: 2,
|
|
maxLines: 4,
|
|
decoration: InputDecoration(hintText: hintText),
|
|
),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () {
|
|
final String value = controller.text.trim();
|
|
if (value.isEmpty) {
|
|
return;
|
|
}
|
|
Navigator.of(context).pop(value);
|
|
},
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
controller.dispose();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
class _EmptyPeopleView extends StatelessWidget {
|
|
const _EmptyPeopleView({required this.onAdd});
|
|
|
|
final VoidCallback onAdd;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: FrostedCard(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
Text(
|
|
'No people yet',
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Add the first relationship profile to start tracking moments.',
|
|
style: Theme.of(
|
|
context,
|
|
).textTheme.bodyLarge?.copyWith(color: AppTheme.textSecondary),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 12),
|
|
FilledButton.icon(
|
|
onPressed: onAdd,
|
|
icon: const Icon(Icons.person_add_alt_1_rounded),
|
|
label: const Text('Add Person'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PersonDetail extends StatelessWidget {
|
|
const _PersonDetail({
|
|
required this.person,
|
|
required this.onEdit,
|
|
required this.onDelete,
|
|
required this.onQuickAction,
|
|
this.compact = false,
|
|
});
|
|
|
|
final PersonProfile person;
|
|
final VoidCallback onEdit;
|
|
final VoidCallback onDelete;
|
|
final ValueChanged<_PersonQuickAction> onQuickAction;
|
|
final bool compact;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
if (compact)
|
|
Column(
|
|
children: <Widget>[
|
|
Row(
|
|
children: <Widget>[
|
|
_AvatarSeed(name: person.name, size: 56),
|
|
const SizedBox(width: 14),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
person.name,
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
person.relationship,
|
|
style: Theme.of(context).textTheme.bodyLarge
|
|
?.copyWith(color: AppTheme.textSecondary),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
PopupMenuButton<_PersonQuickAction>(
|
|
tooltip: 'Quick add',
|
|
onSelected: onQuickAction,
|
|
itemBuilder: (BuildContext context) =>
|
|
const <PopupMenuEntry<_PersonQuickAction>>[
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.capture,
|
|
child: Text('Add Capture'),
|
|
),
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.note,
|
|
child: Text('Add Note'),
|
|
),
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.idea,
|
|
child: Text('Add Idea'),
|
|
),
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.reminder,
|
|
child: Text('Add Reminder'),
|
|
),
|
|
],
|
|
icon: const Icon(Icons.add_circle_outline_rounded),
|
|
),
|
|
IconButton(
|
|
onPressed: onEdit,
|
|
icon: const Icon(Icons.edit_rounded),
|
|
tooltip: 'Edit person',
|
|
),
|
|
IconButton(
|
|
onPressed: onDelete,
|
|
icon: const Icon(Icons.delete_outline_rounded),
|
|
tooltip: 'Delete person',
|
|
),
|
|
],
|
|
),
|
|
],
|
|
)
|
|
else
|
|
Row(
|
|
children: <Widget>[
|
|
_AvatarSeed(name: person.name, size: 64),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
person.name,
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
person.relationship,
|
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
|
color: AppTheme.textSecondary,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
PopupMenuButton<_PersonQuickAction>(
|
|
tooltip: 'Quick add',
|
|
onSelected: onQuickAction,
|
|
itemBuilder: (BuildContext context) =>
|
|
const <PopupMenuEntry<_PersonQuickAction>>[
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.capture,
|
|
child: Text('Add Capture'),
|
|
),
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.note,
|
|
child: Text('Add Note'),
|
|
),
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.idea,
|
|
child: Text('Add Idea'),
|
|
),
|
|
PopupMenuItem<_PersonQuickAction>(
|
|
value: _PersonQuickAction.reminder,
|
|
child: Text('Add Reminder'),
|
|
),
|
|
],
|
|
icon: const Icon(Icons.add_circle_outline_rounded),
|
|
),
|
|
IconButton(
|
|
onPressed: onEdit,
|
|
icon: const Icon(Icons.edit_rounded),
|
|
tooltip: 'Edit person',
|
|
),
|
|
IconButton(
|
|
onPressed: onDelete,
|
|
icon: const Icon(Icons.delete_outline_rounded),
|
|
tooltip: 'Delete person',
|
|
),
|
|
],
|
|
),
|
|
if ((person.location ?? '').trim().isNotEmpty) ...<Widget>[
|
|
SizedBox(height: compact ? 10 : 14),
|
|
Text('Location', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
_DetailTag(label: person.location!.trim()),
|
|
],
|
|
SizedBox(height: compact ? 14 : 22),
|
|
Text('Next moment', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
_DetailTag(
|
|
label:
|
|
'${person.nextMoment.year}-${person.nextMoment.month.toString().padLeft(2, '0')}-${person.nextMoment.day.toString().padLeft(2, '0')} ${person.nextMoment.hour.toString().padLeft(2, '0')}:${person.nextMoment.minute.toString().padLeft(2, '0')}',
|
|
),
|
|
const SizedBox(height: 18),
|
|
Text('Preferences', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: person.tags
|
|
.map((String tag) => _DetailTag(label: tag))
|
|
.toList(growable: false),
|
|
),
|
|
const SizedBox(height: 18),
|
|
Text('Notes', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
person.notes,
|
|
style: Theme.of(
|
|
context,
|
|
).textTheme.bodyLarge?.copyWith(color: AppTheme.textSecondary),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PeopleHeader extends StatelessWidget {
|
|
const _PeopleHeader({required this.onAdd, required this.compact});
|
|
|
|
final VoidCallback onAdd;
|
|
final bool compact;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final TextTheme textTheme = Theme.of(context).textTheme;
|
|
if (compact) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text('People', style: textTheme.headlineMedium),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
'Track what matters to each relationship and follow through.',
|
|
style: textTheme.bodyLarge?.copyWith(color: AppTheme.textSecondary),
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 12),
|
|
FilledButton.icon(
|
|
onPressed: onAdd,
|
|
icon: const Icon(Icons.person_add_alt_1_rounded),
|
|
label: const Text('Add person'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
return Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text('People', style: textTheme.headlineMedium),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
'Track what matters to each relationship and follow through.',
|
|
style: textTheme.bodyLarge?.copyWith(
|
|
color: AppTheme.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
FilledButton.icon(
|
|
onPressed: onAdd,
|
|
icon: const Icon(Icons.person_add_alt_1_rounded),
|
|
label: const Text('Add'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PersonListItem extends StatelessWidget {
|
|
const _PersonListItem({
|
|
required this.person,
|
|
required this.selectedId,
|
|
required this.onSelect,
|
|
});
|
|
|
|
final PersonProfile person;
|
|
final String selectedId;
|
|
final VoidCallback onSelect;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bool isSelected = person.id == selectedId;
|
|
return InkWell(
|
|
onTap: onSelect,
|
|
borderRadius: BorderRadius.circular(20),
|
|
child: FrostedCard(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
children: <Widget>[
|
|
_AvatarSeed(name: person.name),
|
|
const SizedBox(width: 14),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
person.name,
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
person.relationship,
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: AppTheme.textSecondary,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_ScorePill(score: person.affinityScore),
|
|
if (isSelected)
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 10),
|
|
child: Icon(Icons.check_circle, color: Color(0xFF1AB6C8)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PersonEditorDialog extends StatefulWidget {
|
|
const _PersonEditorDialog({required this.title, this.initial});
|
|
|
|
final String title;
|
|
final _PersonDraft? initial;
|
|
|
|
@override
|
|
State<_PersonEditorDialog> createState() => _PersonEditorDialogState();
|
|
}
|
|
|
|
class _PersonEditorDialogState extends State<_PersonEditorDialog> {
|
|
late final TextEditingController _nameController;
|
|
late final TextEditingController _relationshipController;
|
|
late final TextEditingController _locationController;
|
|
late final TextEditingController _tagsController;
|
|
late final TextEditingController _notesController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_nameController = TextEditingController(text: widget.initial?.name ?? '');
|
|
_relationshipController = TextEditingController(
|
|
text: widget.initial?.relationship ?? '',
|
|
);
|
|
_locationController = TextEditingController(
|
|
text: widget.initial?.location ?? '',
|
|
);
|
|
_tagsController = TextEditingController(
|
|
text: widget.initial?.tags.join(', ') ?? '',
|
|
);
|
|
_notesController = TextEditingController(text: widget.initial?.notes ?? '');
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_nameController.dispose();
|
|
_relationshipController.dispose();
|
|
_locationController.dispose();
|
|
_tagsController.dispose();
|
|
_notesController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(widget.title),
|
|
content: SingleChildScrollView(
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 420),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
TextField(
|
|
controller: _nameController,
|
|
decoration: const InputDecoration(labelText: 'Name'),
|
|
),
|
|
TextField(
|
|
controller: _relationshipController,
|
|
decoration: const InputDecoration(labelText: 'Relationship'),
|
|
),
|
|
TextField(
|
|
controller: _locationController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Location (optional)',
|
|
),
|
|
),
|
|
TextField(
|
|
controller: _tagsController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Tags (comma separated)',
|
|
),
|
|
),
|
|
TextField(
|
|
controller: _notesController,
|
|
maxLines: 3,
|
|
decoration: const InputDecoration(labelText: 'Notes'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () {
|
|
final String name = _nameController.text.trim();
|
|
final String relationship = _relationshipController.text.trim();
|
|
if (name.isEmpty || relationship.isEmpty) {
|
|
return;
|
|
}
|
|
|
|
final _PersonDraft draft = _PersonDraft(
|
|
name: name,
|
|
relationship: relationship,
|
|
location: _locationController.text.trim().isEmpty
|
|
? null
|
|
: _locationController.text.trim(),
|
|
notes: _notesController.text.trim(),
|
|
tags: _tagsController.text
|
|
.split(',')
|
|
.map((String tag) => tag.trim())
|
|
.where((String tag) => tag.isNotEmpty)
|
|
.toList(growable: false),
|
|
);
|
|
Navigator.of(context).pop(draft);
|
|
},
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PersonDraft {
|
|
const _PersonDraft({
|
|
required this.name,
|
|
required this.relationship,
|
|
required this.notes,
|
|
required this.tags,
|
|
this.location,
|
|
});
|
|
|
|
final String name;
|
|
final String relationship;
|
|
final String notes;
|
|
final List<String> tags;
|
|
final String? location;
|
|
}
|
|
|
|
class _QuickIdeaDraft {
|
|
const _QuickIdeaDraft({
|
|
required this.type,
|
|
required this.title,
|
|
required this.details,
|
|
});
|
|
|
|
final IdeaType type;
|
|
final String title;
|
|
final String details;
|
|
}
|
|
|
|
class _QuickIdeaDialog extends StatefulWidget {
|
|
const _QuickIdeaDialog();
|
|
|
|
@override
|
|
State<_QuickIdeaDialog> createState() => _QuickIdeaDialogState();
|
|
}
|
|
|
|
class _QuickIdeaDialogState extends State<_QuickIdeaDialog> {
|
|
IdeaType _type = IdeaType.gift;
|
|
final TextEditingController _titleController = TextEditingController();
|
|
final TextEditingController _detailsController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_titleController.dispose();
|
|
_detailsController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: const Text('Add Idea'),
|
|
content: SingleChildScrollView(
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 420),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
SegmentedButton<IdeaType>(
|
|
segments: const <ButtonSegment<IdeaType>>[
|
|
ButtonSegment<IdeaType>(
|
|
value: IdeaType.gift,
|
|
label: Text('Gift'),
|
|
),
|
|
ButtonSegment<IdeaType>(
|
|
value: IdeaType.event,
|
|
label: Text('Event'),
|
|
),
|
|
],
|
|
selected: <IdeaType>{_type},
|
|
onSelectionChanged: (Set<IdeaType> values) {
|
|
setState(() {
|
|
_type = values.first;
|
|
});
|
|
},
|
|
),
|
|
const SizedBox(height: 10),
|
|
TextField(
|
|
controller: _titleController,
|
|
decoration: const InputDecoration(labelText: 'Title'),
|
|
),
|
|
TextField(
|
|
controller: _detailsController,
|
|
maxLines: 3,
|
|
decoration: const InputDecoration(labelText: 'Details'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () {
|
|
final String title = _titleController.text.trim();
|
|
if (title.isEmpty) {
|
|
return;
|
|
}
|
|
Navigator.of(context).pop(
|
|
_QuickIdeaDraft(
|
|
type: _type,
|
|
title: title,
|
|
details: _detailsController.text.trim(),
|
|
),
|
|
);
|
|
},
|
|
child: const Text('Add'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _QuickReminderDraft {
|
|
const _QuickReminderDraft({
|
|
required this.title,
|
|
required this.cadence,
|
|
required this.nextAt,
|
|
});
|
|
|
|
final String title;
|
|
final ReminderCadence cadence;
|
|
final DateTime nextAt;
|
|
}
|
|
|
|
class _QuickReminderDialog extends StatefulWidget {
|
|
const _QuickReminderDialog();
|
|
|
|
@override
|
|
State<_QuickReminderDialog> createState() => _QuickReminderDialogState();
|
|
}
|
|
|
|
class _QuickReminderDialogState extends State<_QuickReminderDialog> {
|
|
final TextEditingController _titleController = TextEditingController();
|
|
ReminderCadence _cadence = ReminderCadence.weekly;
|
|
DateTime _nextAt = DateTime.now().add(const Duration(days: 1));
|
|
|
|
@override
|
|
void dispose() {
|
|
_titleController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: const Text('Add Reminder'),
|
|
content: SingleChildScrollView(
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 420),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
TextField(
|
|
controller: _titleController,
|
|
decoration: const InputDecoration(labelText: 'Title'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
DropdownButtonFormField<ReminderCadence>(
|
|
initialValue: _cadence,
|
|
decoration: const InputDecoration(labelText: 'Cadence'),
|
|
items: ReminderCadence.values
|
|
.map(
|
|
(ReminderCadence cadence) =>
|
|
DropdownMenuItem<ReminderCadence>(
|
|
value: cadence,
|
|
child: Text(cadence.name),
|
|
),
|
|
)
|
|
.toList(growable: false),
|
|
onChanged: (ReminderCadence? value) {
|
|
if (value == null) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
_cadence = value;
|
|
});
|
|
},
|
|
),
|
|
const SizedBox(height: 10),
|
|
Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: Text(
|
|
'Next: ${_nextAt.year}-${_nextAt.month.toString().padLeft(2, '0')}-${_nextAt.day.toString().padLeft(2, '0')} ${_nextAt.hour.toString().padLeft(2, '0')}:${_nextAt.minute.toString().padLeft(2, '0')}',
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
final DateTime now = DateTime.now();
|
|
final DateTime? date = await showDatePicker(
|
|
context: context,
|
|
firstDate: now,
|
|
lastDate: now.add(const Duration(days: 3650)),
|
|
initialDate: _nextAt,
|
|
);
|
|
if (date == null || !context.mounted) {
|
|
return;
|
|
}
|
|
final TimeOfDay? time = await showTimePicker(
|
|
context: context,
|
|
initialTime: TimeOfDay.fromDateTime(_nextAt),
|
|
);
|
|
if (time == null) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
_nextAt = DateTime(
|
|
date.year,
|
|
date.month,
|
|
date.day,
|
|
time.hour,
|
|
time.minute,
|
|
);
|
|
});
|
|
},
|
|
child: const Text('Change'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () {
|
|
final String title = _titleController.text.trim();
|
|
if (title.isEmpty) {
|
|
return;
|
|
}
|
|
Navigator.of(context).pop(
|
|
_QuickReminderDraft(
|
|
title: title,
|
|
cadence: _cadence,
|
|
nextAt: _nextAt,
|
|
),
|
|
);
|
|
},
|
|
child: const Text('Add'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DetailTag extends StatelessWidget {
|
|
const _DetailTag({required this.label});
|
|
|
|
final String label;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF2F8FA),
|
|
borderRadius: BorderRadius.circular(99),
|
|
),
|
|
child: Text(label, style: Theme.of(context).textTheme.bodyMedium),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AvatarSeed extends StatelessWidget {
|
|
const _AvatarSeed({required this.name, this.size = 48});
|
|
|
|
final String name;
|
|
final double size;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final String initials = name
|
|
.split(' ')
|
|
.where((String part) => part.isNotEmpty)
|
|
.take(2)
|
|
.map((String part) => part[0].toUpperCase())
|
|
.join();
|
|
|
|
return Container(
|
|
width: size,
|
|
height: size,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(size / 2),
|
|
gradient: const LinearGradient(
|
|
colors: <Color>[Color(0xFF1AB6C8), Color(0xFF2274E0)],
|
|
),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
initials,
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ScorePill extends StatelessWidget {
|
|
const _ScorePill({required this.score});
|
|
|
|
final int score;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFEEF7F3),
|
|
borderRadius: BorderRadius.circular(99),
|
|
),
|
|
child: Text(
|
|
'$score%',
|
|
style: Theme.of(context).textTheme.labelLarge?.copyWith(
|
|
color: const Color(0xFF1D9C66),
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|