Files
life-helper/app/lib/ui/screens/streak_screen.dart
joungmin 8fe6a8f378 [Developer] #204 Phase 1 MVP — Flutter app skeleton complete
- Drift 21 tables (8 catalog + 11 user + habit_dose_variants + meta_kv)
  with R1~R10 CHECK constraints and 19 indexes
- 8 hand-crafted seed JSON catalogs in app/assets/seed/
  (refs 84, protocols 34, methodologies 21, frame_patterns 30,
   reward_menu_items 30, break_protocols 8, common_frames 5, diet_patterns 5)
- 6 domain functions: recommend_variant, compute_streak,
  validate_frame_level, active_habit_quota, weekly_minimum_ratio,
  seed_importer (transactional, idempotent)
- 4 vertical-slice Riverpod screens: HabitList, HabitCreate, CheckIn, Streak
- 31 unit tests passing; flutter analyze clean
- OQ-5 streak semantics: missing entry ≠ explicit blank
  (missing = end of history; only TrackerValue.blank triggers Never-miss-twice)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-12 10:33:03 +09:00

103 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/time.dart';
import '../../domain/models/tracker_entry.dart';
import '../../domain/streak/compute_streak.dart';
import '../../state/providers.dart';
class StreakScreen extends ConsumerWidget {
final String habitId;
const StreakScreen({super.key, required this.habitId});
@override
Widget build(BuildContext context, WidgetRef ref) {
final db = ref.watch(appDatabaseProvider);
final habitFuture = (db.select(db.habits)
..where((t) => t.id.equals(habitId)))
.getSingle();
final entriesFuture = ref.read(trackerDaoProvider).entriesForHabit(habitId);
return Scaffold(
appBar: AppBar(title: const Text('스트릭')),
body: FutureBuilder(
future: Future.wait([habitFuture, entriesFuture]),
builder: (context, snap) {
if (!snap.hasData) {
return const Center(child: CircularProgressIndicator());
}
if (snap.hasError) {
return Center(child: Text('실패: ${snap.error}'));
}
final habit = snap.data![0] as dynamic;
final entryRows = snap.data![1] as List;
final entries = entryRows.map((r) {
return TrackerEntryModel(
id: r.id as String,
habitId: r.habitId as String,
date: r.date as String,
value: (r.value as String) == 'done'
? TrackerValue.done
: TrackerValue.blank,
variantId: r.variantId as String?,
ctxLocation: r.ctxLocation as String?,
ctxCondition: r.ctxCondition as String?,
note: r.note as String?,
loggedAt: r.loggedAt as String?,
);
}).toList();
final state = computeStreak(
entries: entries,
asOf: nowKst(),
habitStartedAt: habit.startedAt as String,
);
return Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(habit.title as String,
style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 24),
_Row('현재 스트릭', '${state.currentStreak}'),
_Row('최장 스트릭', '${state.longestStreak}'),
_Row('최근 30일 / 완료', '${state.doneCountInWindow30}'),
_Row('Phase 42일 / 완료', '${state.doneCountInPhase42}'),
const Divider(height: 32),
_Row('현재 티어', state.currentTier.dbValue),
if (state.neverMissTwiceBroken)
const Padding(
padding: EdgeInsets.only(top: 12),
child: Text(
'⚠ Never miss twice 발동 — 티어 강등',
style: TextStyle(color: Colors.redAccent),
),
),
],
),
);
},
),
);
}
}
class _Row extends StatelessWidget {
final String label;
final String value;
const _Row(this.label, this.value);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
children: [
Expanded(child: Text(label)),
Text(value, style: const TextStyle(fontWeight: FontWeight.w600)),
],
),
);
}
}