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:
@@ -1,3 +1,4 @@
|
||||
import '../../about/external/data/Goal.dart';
|
||||
import '../../utils/CapacityEngine.dart';
|
||||
|
||||
abstract class ConnectNewCommitment {
|
||||
@@ -9,4 +10,7 @@ abstract class ConnectNewCommitment {
|
||||
/// The learned multiplier for this category, so the estimate field can show
|
||||
/// what the app actually expects the task to take.
|
||||
void onMultiplierResolved(double multiplier);
|
||||
|
||||
/// Goals are loaded; open the picker.
|
||||
void onGoalsReady(List<Goal> goals);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../about/external/data/Goal.dart';
|
||||
import 'NewCommitmentState.dart';
|
||||
|
||||
class NewCommitment extends StatefulWidget {
|
||||
const NewCommitment({super.key});
|
||||
/// The goal this task is created inside; it can still be changed in the
|
||||
/// form. Null starts the task loose.
|
||||
final Goal? goal;
|
||||
|
||||
const NewCommitment({super.key, this.goal});
|
||||
|
||||
@override
|
||||
State<NewCommitment> createState() => NewCommitmentState();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import '../../about/external/data/Commitment.dart';
|
||||
import '../../about/external/data/pages/request/CommitmentsRequest.dart';
|
||||
import '../../about/external/data/pages/request/HistoryRequest.dart';
|
||||
import '../../about/external/data/pages/request/PageAndSort.dart';
|
||||
import '../../about/external/data/pages/request/Pageable.dart';
|
||||
import '../../about/external/data/pages/request/Sort.dart';
|
||||
@@ -7,6 +8,7 @@ import '../../about/external/data/pages/response/CommitmentPage.dart';
|
||||
import '../../about/external/initial/CommitmentRequest.dart';
|
||||
import '../../about/internal/application/CapacityProfile.dart';
|
||||
import '../../utils/CapacityEngine.dart';
|
||||
import '../../utils/ObjectConvertors.dart';
|
||||
import '../parent/ParentViewModel.dart';
|
||||
import 'ConnectNewCommitment.dart';
|
||||
|
||||
@@ -24,6 +26,28 @@ class ViewNewCommitment extends ParentViewModel {
|
||||
connection.onMultiplierResolved(profile.multiplierFor(category));
|
||||
}
|
||||
|
||||
/// Goals for the picker — loaded on tap, never up front.
|
||||
void loadGoals() async {
|
||||
if (!await hasNetwork(() => loadGoals())) return;
|
||||
|
||||
showLoading("Loading goals");
|
||||
|
||||
try {
|
||||
final response = await getDataManager().getMyGoals(HistoryRequest(
|
||||
query: PageAndSort(
|
||||
sort: Sort('desc', 'startDate'),
|
||||
page: Pageable(0, 0, 50, 0),
|
||||
),
|
||||
));
|
||||
|
||||
closeLoading();
|
||||
|
||||
connection.onGoalsReady(getGoalList(response.data));
|
||||
} catch (e) {
|
||||
handleError(e, () => loadGoals(), () => dismissError(), "Retry");
|
||||
}
|
||||
}
|
||||
|
||||
/// The capacity gate. Chronic overdue is usually overcommitment misdiagnosed
|
||||
/// as laziness, so the plan is checked against what history says actually
|
||||
/// gets done before anything is accepted.
|
||||
|
||||
Reference in New Issue
Block a user