내가 쓰는 공부/휴식 시간 조합에 이름을 붙여 공유하고, 다른 학생이 올린 루틴을 목록에서 골라 그대로 적용할 수 있다. 인기순/최신순 정렬, 많이 쓰인 루틴일수록 사용 횟수가 올라가서 눈에 띄게 했다. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
325 lines
12 KiB
Dart
325 lines
12 KiB
Dart
// 🍅 뽀모도로 루틴 공유 화면 (UI 전용). 다른 학생들이 올린 공부/휴식 시간 조합을 보고
|
|
// 그대로 적용하거나, 내가 쓰는 조합을 이름 붙여 공유할 수 있다.
|
|
// 서버 통신/상태는 lib/function/study_preset_controller.dart가 담당한다.
|
|
import 'package:flutter/material.dart';
|
|
import '../function/study_preset_controller.dart';
|
|
import '../theme/app_palette.dart';
|
|
import 'app_notice.dart';
|
|
import 'title_pill.dart';
|
|
|
|
class StudyPresetScreen extends StatefulWidget {
|
|
final String studentId;
|
|
final String studentName;
|
|
final int initialStudyMinutes;
|
|
final int initialBreakMinutes;
|
|
|
|
const StudyPresetScreen({
|
|
super.key,
|
|
required this.studentId,
|
|
required this.studentName,
|
|
required this.initialStudyMinutes,
|
|
required this.initialBreakMinutes,
|
|
});
|
|
|
|
@override
|
|
State<StudyPresetScreen> createState() => _StudyPresetScreenState();
|
|
}
|
|
|
|
class _StudyPresetScreenState extends State<StudyPresetScreen> {
|
|
late final StudyPresetController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = StudyPresetController(
|
|
studentId: widget.studentId,
|
|
studentName: widget.studentName,
|
|
);
|
|
_controller.init();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _apply(dynamic preset) async {
|
|
await _controller.markUsed(preset['id'] as int);
|
|
if (!mounted) return;
|
|
Navigator.of(context).pop({
|
|
'studyMinutes': preset['studyMinutes'] as int,
|
|
'breakMinutes': preset['breakMinutes'] as int,
|
|
});
|
|
}
|
|
|
|
Future<void> _delete(int presetId) async {
|
|
final (_, message) = await _controller.delete(presetId);
|
|
if (!mounted) return;
|
|
AppNotice.show(context, message);
|
|
}
|
|
|
|
Future<void> _showShareDialog() async {
|
|
final titleController = TextEditingController();
|
|
int studyMinutes = widget.initialStudyMinutes;
|
|
int breakMinutes = widget.initialBreakMinutes;
|
|
|
|
await showModalBottomSheet<void>(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
backgroundColor: AppPalette.paper,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
|
),
|
|
builder: (sheetContext) {
|
|
return StatefulBuilder(
|
|
builder: (sheetContext, setSheetState) {
|
|
return Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 20,
|
|
right: 20,
|
|
top: 20,
|
|
bottom: MediaQuery.of(sheetContext).viewInsets.bottom + 20,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const Text(
|
|
'내 루틴 공유하기',
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextField(
|
|
controller: titleController,
|
|
maxLength: 30,
|
|
decoration: InputDecoration(
|
|
hintText: '루틴 이름 (예: 불태우는 금요일)',
|
|
filled: true,
|
|
fillColor: AppPalette.mist,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
),
|
|
),
|
|
_minuteRow(
|
|
label: '공부 시간',
|
|
minutes: studyMinutes,
|
|
onChanged: (v) => setSheetState(() => studyMinutes = v),
|
|
),
|
|
_minuteRow(
|
|
label: '휴식 시간',
|
|
minutes: breakMinutes,
|
|
onChanged: (v) => setSheetState(() => breakMinutes = v),
|
|
),
|
|
const SizedBox(height: 12),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
),
|
|
onPressed: () async {
|
|
final (success, message) = await _controller.share(
|
|
title: titleController.text,
|
|
studyMinutes: studyMinutes,
|
|
breakMinutes: breakMinutes,
|
|
);
|
|
if (sheetContext.mounted) {
|
|
Navigator.of(sheetContext).pop();
|
|
}
|
|
if (!mounted) return;
|
|
AppNotice.show(
|
|
context,
|
|
message,
|
|
icon: success
|
|
? Icons.check_circle_rounded
|
|
: Icons.error_outline_rounded,
|
|
);
|
|
},
|
|
child: const Text('공유하기'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _minuteRow({
|
|
required String label,
|
|
required int minutes,
|
|
required ValueChanged<int> onChanged,
|
|
}) {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
label,
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.remove_circle_outline_rounded),
|
|
onPressed: minutes > 5 ? () => onChanged(minutes - 5) : null,
|
|
),
|
|
SizedBox(
|
|
width: 48,
|
|
child: Text(
|
|
'$minutes분',
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.add_circle_outline_rounded),
|
|
onPressed: minutes < 120 ? () => onChanged(minutes + 5) : null,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: _controller,
|
|
builder: (context, _) {
|
|
final presets = _controller.presets;
|
|
return Scaffold(
|
|
backgroundColor: AppPalette.mist,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
foregroundColor: AppPalette.ink,
|
|
elevation: 0,
|
|
centerTitle: true,
|
|
title: const TitlePill('뽀모도로 루틴 공유'),
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
onPressed: _showShareDialog,
|
|
icon: const Icon(Icons.ios_share_rounded),
|
|
label: const Text('내 루틴 공유'),
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
|
child: Row(
|
|
children: [
|
|
_sortChip('popular', '인기순'),
|
|
const SizedBox(width: 8),
|
|
_sortChip('recent', '최신순'),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: _controller.isLoading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: presets.isEmpty
|
|
? const Center(
|
|
child: Text(
|
|
'아직 공유된 루틴이 없어요.\n첫 루틴을 공유해보세요.',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 8,
|
|
),
|
|
itemCount: presets.length,
|
|
itemBuilder: (context, index) {
|
|
final preset = presets[index];
|
|
final bool isMine =
|
|
preset['studentId'] == widget.studentId;
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: AppPalette.paper,
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(color: AppPalette.sage),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
preset['title'] ?? '',
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 15,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'공부 ${preset['studyMinutes']}분 · 휴식 ${preset['breakMinutes']}분',
|
|
style: const TextStyle(
|
|
color: AppPalette.ink,
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'${preset['studentName'] ?? ''} · 사용 ${preset['useCount'] ?? 0}회',
|
|
style: const TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 11.5,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (isMine)
|
|
IconButton(
|
|
icon: const Icon(
|
|
Icons.delete_outline_rounded,
|
|
color: Colors.grey,
|
|
),
|
|
onPressed: () =>
|
|
_delete(preset['id'] as int),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
),
|
|
onPressed: () => _apply(preset),
|
|
child: const Text('적용'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _sortChip(String value, String label) {
|
|
final bool selected = _controller.sort == value;
|
|
return ChoiceChip(
|
|
label: Text(label),
|
|
selected: selected,
|
|
onSelected: (_) => _controller.setSort(value),
|
|
selectedColor: AppPalette.ink,
|
|
labelStyle: TextStyle(
|
|
color: selected ? Colors.white : AppPalette.ink,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
);
|
|
}
|
|
}
|