ADR-0005 in-process tool runtime — 6 tools (catalog 2 + tracker 2 + habit 2), ToolDispatcher with JSON-schema validation + modal ConfirmGate for destructive ops, multi-turn LlmChatSession abstraction wired to flutter_gemma 0.16.5 (ToolChoice.auto), ChatSessionController with MAX_TURNS=4 safety + 8-turn history hint, ChatScreen entry behind AI opt-in. R3/R7/R8 enforced inside handlers. 41 new tests (envelope, catalog/tracker/habit tools, dispatcher, controller loop) — 151 total passing. Refs #260
129 lines
4.4 KiB
Dart
129 lines
4.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../state/ai_providers.dart';
|
|
import '../../state/providers.dart';
|
|
import 'chat_screen.dart';
|
|
import 'check_in_screen.dart';
|
|
import 'habit_create_screen.dart';
|
|
import 'protocol_gallery_screen.dart';
|
|
import 'settings_screen.dart';
|
|
import 'streak_screen.dart';
|
|
|
|
class HabitListScreen extends ConsumerWidget {
|
|
const HabitListScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final boot = ref.watch(bootstrapProvider);
|
|
final habitsAsync = ref.watch(activeHabitsProvider);
|
|
final aiOptIn = ref.watch(aiSettingsProvider).valueOrNull ?? false;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('습관'),
|
|
actions: [
|
|
if (aiOptIn)
|
|
IconButton(
|
|
icon: const Icon(Icons.smart_toy_outlined),
|
|
tooltip: 'AI 코치',
|
|
onPressed: () {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (_) => const ChatScreen(),
|
|
));
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.search),
|
|
tooltip: '카탈로그 탐색',
|
|
onPressed: () => _openGallery(context),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.settings),
|
|
tooltip: '설정',
|
|
onPressed: () {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (_) => const SettingsScreen(),
|
|
));
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: boot.when(
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (e, st) => Center(child: Text('초기화 실패: $e')),
|
|
data: (_) => habitsAsync.when(
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (e, st) => Center(child: Text('로드 실패: $e')),
|
|
data: (habits) {
|
|
if (habits.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 24),
|
|
child: Text(
|
|
'아직 습관이 없습니다.\n+ 버튼으로 추가하거나, 카탈로그에서 골라보세요.',
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
FilledButton.icon(
|
|
onPressed: () => _openGallery(context),
|
|
icon: const Icon(Icons.search),
|
|
label: const Text('🔍 카탈로그 탐색'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
return ListView.separated(
|
|
itemCount: habits.length,
|
|
separatorBuilder: (_, _) => const Divider(height: 1),
|
|
itemBuilder: (context, i) {
|
|
final h = habits[i];
|
|
return ListTile(
|
|
title: Text(h.title),
|
|
subtitle: Text(
|
|
'${h.type} · ${h.frameLevel} · ${h.frameFramedText}',
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
trailing: IconButton(
|
|
icon: const Icon(Icons.show_chart),
|
|
onPressed: () {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (_) => StreakScreen(habitId: h.id),
|
|
));
|
|
},
|
|
),
|
|
onTap: () {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (_) => CheckInScreen(habitId: h.id),
|
|
));
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (_) => const HabitCreateScreen(),
|
|
));
|
|
},
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _openGallery(BuildContext context) {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (_) => const ProtocolGalleryScreen(),
|
|
));
|
|
}
|
|
}
|