Files
GroundedHelper/frontend/lib/Grounded/about/external/data/GroupGoal.dart
alvocool 4b71257429 Add groups with shared goals, objectives and chat; drop the water tracker
Groups let people keep each other honest: create one or join with a
six-letter invite code. Each group has shared goals split into measurable
objectives (km, sessions, words) that every member logs toward, a
leaderboard of kept rate and streak with nudges, and a group chat where
check-ins and nudges appear as cards beside the talk. The open chat polls
for new messages.

Reached from a new Groups tab (Training moves into the day rail), a Home
"Your groups" rail that opens the chat, and a Group tile in the add sheet.
Mock mode seeds two groups, a joinable one and members who reply.

The water tracker is removed; it did not fit the app. Bottom sheets are
now square app-wide via the theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KhQh614DMeYoQEH9SoMRUw
2026-11-03 11:46:41 +03:00

68 lines
1.8 KiB
Dart

import '../../../utils/ObjectConvertors.dart';
import 'GroupObjective.dart';
/// A goal the whole group shares, broken into objectives everyone logs
/// against. Like a personal goal it carries no debt of its own.
class GroupGoal {
String id;
String title;
String description;
DateTime? targetDate;
String colourHex;
List<GroupObjective> objectives;
GroupGoal({
this.id = "",
this.title = "",
this.description = "",
this.targetDate,
this.colourHex = "",
List<GroupObjective>? objectives,
}) : objectives = objectives ?? <GroupObjective>[];
/// The average of the objectives, so one runaway objective cannot carry
/// the rest.
double get progress {
if (objectives.isEmpty) {
return 0;
}
double total = 0;
for (GroupObjective objective in objectives) {
total = total + objective.progress;
}
return total / objectives.length;
}
int get completeObjectives =>
objectives.where((objective) => objective.complete).length;
factory GroupGoal.fromJson(Map<String, dynamic> json) {
return GroupGoal(
id: json['id'] ?? "",
title: json['title'] ?? "",
description: json['description'] ?? "",
targetDate: json['targetDate'] == null || json['targetDate'] == ""
? null
: DateTime.tryParse(json['targetDate']),
colourHex: json['colourHex'] ?? "",
objectives: getGroupObjectiveList(json['objectives']),
);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['title'] = title;
data['description'] = description;
data['targetDate'] = targetDate?.toIso8601String();
data['colourHex'] = colourHex;
data['objectives'] = objectives.map((item) => item.toJson()).toList();
return data;
}
}