Add routines module and full goal management

Routines: workout, meditation and must-do routines with timed, rep and
tick steps, sets and rest. A library screen, a builder with templates
and drag-to-reorder steps, and a full-screen player that auto-advances
timed phases, counts backgrounding and logs broken chains as partial.

Goals: a goal editor (deadline, colour, category, default class, archive),
routines linked to goals, and a goal field on tasks and routines. Tasks
added from inside a goal are now actually attached to it via parentId.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KhQh614DMeYoQEH9SoMRUw
This commit is contained in:
alvocool
2026-11-02 08:45:41 +03:00
parent c88887b639
commit 1a5867a98f
49 changed files with 5384 additions and 220 deletions

View File

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import '../../about/external/data/Commitment.dart';
import '../../about/external/data/Goal.dart';
import '../../about/external/initial/CommitmentRequest.dart';
import '../../about/internal/application/CommitmentClass.dart';
import '../../about/internal/application/EnergyCost.dart';
@@ -10,6 +11,7 @@ import '../../about/internal/application/NotificationType.dart';
import '../../about/internal/application/ProofType.dart';
import '../../about/internal/application/TextType.dart';
import '../../designs/Component.dart';
import '../../designs/GoalPicker.dart';
import '../../designs/Responsive.dart';
import '../../designs/Shell.dart';
import '../../designs/buttons/Buttons.dart';
@@ -49,6 +51,9 @@ class NewCommitmentState extends State<NewCommitment>
String _windowError = "";
/// The goal this task belongs to; null for a loose task.
Goal? _goal;
@override
Widget build(BuildContext context) {
return ViewModelBuilder<ViewNewCommitment>.reactive(
@@ -76,6 +81,11 @@ class NewCommitmentState extends State<NewCommitment>
setState(() {
_windowStart = now;
_windowEnd = now.add(const Duration(hours: 2));
// A task made inside a goal starts in it, at the goal's default weight.
if (widget.goal != null) {
_goal = widget.goal;
_class = widget.goal!.defaultClass;
}
});
}
@@ -85,6 +95,10 @@ class NewCommitmentState extends State<NewCommitment>
Navigator.pop(context, false);
}
void _onPickGoal() {
_model?.loadGoals();
}
void _onCategoryChanged(String value) {
_model?.resolveMultiplier(value.trim());
}
@@ -185,6 +199,7 @@ class NewCommitmentState extends State<NewCommitment>
CommitmentRequest _buildRequest() {
return CommitmentRequest(
parentId: _goal?.id,
commitmentClass: _class.name,
title: _title.text.trim(),
category: _category.text.trim(),
@@ -200,6 +215,7 @@ class NewCommitmentState extends State<NewCommitment>
Commitment _buildCandidate() {
return Commitment(
parentId: _goal?.id,
commitmentClass: _class,
title: _title.text.trim(),
category: _category.text.trim(),
@@ -237,6 +253,14 @@ class NewCommitmentState extends State<NewCommitment>
validator: Validators.title,
),
const SizedBox(height: 20),
selectField(
"Goal",
_goal?.title ?? "",
_onPickGoal,
hint: "No goal — a loose task",
icon: CupertinoIcons.flag,
),
const SizedBox(height: 20),
inputField(
"Category",
_category,
@@ -542,6 +566,20 @@ class NewCommitmentState extends State<NewCommitment>
});
}
@override
void onGoalsReady(List<Goal> goals) async {
final Goal? picked =
await showGoalPicker(context, goals, selectedId: _goal?.id);
if (picked == null || !mounted) {
return;
}
setState(() {
_goal = picked.id == null ? null : picked;
});
}
@override
void dispose() {
_title.dispose();