first commit
This commit is contained in:
129
lib/screens/complete_screen.dart
Normal file
129
lib/screens/complete_screen.dart
Normal file
@@ -0,0 +1,129 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_text_styles.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../services/encouragement_service.dart';
|
||||
import 'home_screen.dart';
|
||||
import 'history_screen.dart';
|
||||
|
||||
/// Complete Screen - Shows after focus session ends
|
||||
class CompleteScreen extends StatelessWidget {
|
||||
final int focusedMinutes;
|
||||
final int distractionCount;
|
||||
final EncouragementService encouragementService;
|
||||
|
||||
const CompleteScreen({
|
||||
super.key,
|
||||
required this.focusedMinutes,
|
||||
required this.distractionCount,
|
||||
required this.encouragementService,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final storageService = StorageService();
|
||||
final todayTotal = storageService.getTodayTotalMinutes();
|
||||
final todayDistractions = storageService.getTodayDistractionCount();
|
||||
final encouragement = encouragementService.getRandomMessage();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Success Icon
|
||||
const Text(
|
||||
'✨',
|
||||
style: TextStyle(fontSize: 64),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// You focused for X minutes
|
||||
Text(
|
||||
'You focused for',
|
||||
style: AppTextStyles.headline,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'$focusedMinutes ${focusedMinutes == 1 ? 'minute' : 'minutes'}',
|
||||
style: AppTextStyles.largeNumber,
|
||||
),
|
||||
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// Stats Card
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Total Today: $todayTotal mins',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Distractions: $todayDistractions ${todayDistractions == 1 ? 'time' : 'times'}',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'"$encouragement"',
|
||||
style: AppTextStyles.encouragementQuote,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// Start Another Button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => HomeScreen(
|
||||
encouragementService: encouragementService,
|
||||
),
|
||||
),
|
||||
(route) => false,
|
||||
);
|
||||
},
|
||||
child: const Text('Start Another'),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// View Full Report - Navigate to History
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const HistoryScreen(),
|
||||
),
|
||||
(route) => route.isFirst, // Keep only the home screen in stack
|
||||
);
|
||||
},
|
||||
child: const Text('View History'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
358
lib/screens/focus_screen.dart
Normal file
358
lib/screens/focus_screen.dart
Normal file
@@ -0,0 +1,358 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_text_styles.dart';
|
||||
import '../models/distraction_type.dart';
|
||||
import '../models/focus_session.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../services/encouragement_service.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import 'complete_screen.dart';
|
||||
|
||||
/// Focus Screen - Timer and distraction tracking
|
||||
class FocusScreen extends StatefulWidget {
|
||||
final int durationMinutes;
|
||||
final EncouragementService encouragementService;
|
||||
|
||||
const FocusScreen({
|
||||
super.key,
|
||||
required this.durationMinutes,
|
||||
required this.encouragementService,
|
||||
});
|
||||
|
||||
@override
|
||||
State<FocusScreen> createState() => _FocusScreenState();
|
||||
}
|
||||
|
||||
class _FocusScreenState extends State<FocusScreen> {
|
||||
late Timer _timer;
|
||||
late int _remainingSeconds;
|
||||
late DateTime _startTime;
|
||||
final List<String> _distractions = [];
|
||||
bool _isPaused = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_remainingSeconds = widget.durationMinutes * 60;
|
||||
_startTime = DateTime.now();
|
||||
_startTimer();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (!_isPaused && _remainingSeconds > 0) {
|
||||
setState(() {
|
||||
_remainingSeconds--;
|
||||
});
|
||||
|
||||
if (_remainingSeconds == 0) {
|
||||
_onTimerComplete();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _onTimerComplete() async {
|
||||
_timer.cancel();
|
||||
_saveFocusSession(completed: true);
|
||||
|
||||
// Send notification
|
||||
final notificationService = NotificationService();
|
||||
await notificationService.showFocusCompletedNotification(
|
||||
minutes: widget.durationMinutes,
|
||||
distractionCount: _distractions.length,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CompleteScreen(
|
||||
focusedMinutes: widget.durationMinutes,
|
||||
distractionCount: _distractions.length,
|
||||
encouragementService: widget.encouragementService,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _togglePause() {
|
||||
setState(() {
|
||||
_isPaused = !_isPaused;
|
||||
});
|
||||
}
|
||||
|
||||
void _stopEarly() {
|
||||
final actualMinutes = ((widget.durationMinutes * 60 - _remainingSeconds) / 60).floor();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Stop early?'),
|
||||
content: Text(
|
||||
"That's totally fine — you still focused for $actualMinutes ${actualMinutes == 1 ? 'minute' : 'minutes'}!",
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Keep going'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Close dialog
|
||||
_timer.cancel();
|
||||
_saveFocusSession(completed: false);
|
||||
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CompleteScreen(
|
||||
focusedMinutes: actualMinutes,
|
||||
distractionCount: _distractions.length,
|
||||
encouragementService: widget.encouragementService,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Yes, stop'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _saveFocusSession({required bool completed}) async {
|
||||
final actualMinutes = completed
|
||||
? widget.durationMinutes
|
||||
: ((widget.durationMinutes * 60 - _remainingSeconds) / 60).floor();
|
||||
|
||||
final session = FocusSession(
|
||||
startTime: _startTime,
|
||||
durationMinutes: widget.durationMinutes,
|
||||
actualMinutes: actualMinutes,
|
||||
distractionCount: _distractions.length,
|
||||
completed: completed,
|
||||
distractionTypes: _distractions,
|
||||
);
|
||||
|
||||
final storageService = StorageService();
|
||||
await storageService.saveFocusSession(session);
|
||||
}
|
||||
|
||||
void _showDistractionSheet() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: AppColors.white,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
builder: (context) {
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Drag handle
|
||||
Center(
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.distractionButton,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Title
|
||||
const Text(
|
||||
'What pulled you away?',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Distraction options
|
||||
...DistractionType.all.map((type) {
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Text(
|
||||
DistractionType.getEmoji(type),
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
title: Text(
|
||||
DistractionType.getDisplayName(type),
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_recordDistraction(type);
|
||||
},
|
||||
),
|
||||
if (type != DistractionType.all.last)
|
||||
const Divider(color: AppColors.divider),
|
||||
],
|
||||
);
|
||||
}),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Skip button
|
||||
Center(
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_recordDistraction(null);
|
||||
},
|
||||
child: const Text('Skip this time'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _recordDistraction(String? type) {
|
||||
setState(() {
|
||||
if (type != null) {
|
||||
_distractions.add(type);
|
||||
}
|
||||
});
|
||||
|
||||
// Show encouragement toast
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("It happens. Let's gently come back."),
|
||||
duration: Duration(seconds: 2),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatTime(int seconds) {
|
||||
final minutes = seconds ~/ 60;
|
||||
final secs = seconds % 60;
|
||||
return '${minutes.toString().padLeft(2, '0')}:${secs.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Spacer(),
|
||||
|
||||
// Timer Display
|
||||
Text(
|
||||
_formatTime(_remainingSeconds),
|
||||
style: AppTextStyles.timerDisplay,
|
||||
),
|
||||
|
||||
const SizedBox(height: 80),
|
||||
|
||||
// "I got distracted" Button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _showDistractionSheet,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.distractionButton,
|
||||
foregroundColor: AppColors.textPrimary,
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'I got distracted',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'🤚',
|
||||
style: const TextStyle(fontSize: 20),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Pause Button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton(
|
||||
onPressed: _togglePause,
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: AppColors.primary,
|
||||
side: const BorderSide(color: AppColors.primary, width: 1),
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(_isPaused ? Icons.play_arrow : Icons.pause),
|
||||
const SizedBox(width: 8),
|
||||
Text(_isPaused ? 'Resume' : 'Pause'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// Stop Button (text button at bottom)
|
||||
TextButton(
|
||||
onPressed: _stopEarly,
|
||||
child: const Text(
|
||||
'Stop session',
|
||||
style: TextStyle(
|
||||
color: AppColors.textSecondary,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
344
lib/screens/history_screen.dart
Normal file
344
lib/screens/history_screen.dart
Normal file
@@ -0,0 +1,344 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_text_styles.dart';
|
||||
import '../models/focus_session.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// History Screen - Shows past focus sessions
|
||||
class HistoryScreen extends StatefulWidget {
|
||||
const HistoryScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HistoryScreen> createState() => _HistoryScreenState();
|
||||
}
|
||||
|
||||
class _HistoryScreenState extends State<HistoryScreen> {
|
||||
final StorageService _storageService = StorageService();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sessions = _storageService.getAllSessions();
|
||||
final todayTotal = _storageService.getTodayTotalMinutes();
|
||||
final todayDistractions = _storageService.getTodayDistractionCount();
|
||||
final todayCompleted = _storageService.getTodayCompletedCount();
|
||||
|
||||
// Group sessions by date
|
||||
final sessionsByDate = <DateTime, List<FocusSession>>{};
|
||||
for (final session in sessions) {
|
||||
final date = DateTime(
|
||||
session.startTime.year,
|
||||
session.startTime.month,
|
||||
session.startTime.day,
|
||||
);
|
||||
if (!sessionsByDate.containsKey(date)) {
|
||||
sessionsByDate[date] = [];
|
||||
}
|
||||
sessionsByDate[date]!.add(session);
|
||||
}
|
||||
|
||||
// Sort dates (newest first)
|
||||
final sortedDates = sessionsByDate.keys.toList()
|
||||
..sort((a, b) => b.compareTo(a));
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
title: const Text('Your Focus Journey'),
|
||||
backgroundColor: AppColors.background,
|
||||
),
|
||||
body: sessions.isEmpty
|
||||
? _buildEmptyState(context)
|
||||
: ListView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
children: [
|
||||
// Today's Summary Card
|
||||
_buildTodaySummary(
|
||||
todayTotal,
|
||||
todayDistractions,
|
||||
todayCompleted,
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Sessions by date
|
||||
...sortedDates.map((date) {
|
||||
final dateSessions = sessionsByDate[date]!;
|
||||
return _buildDateSection(date, dateSessions);
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'📊',
|
||||
style: TextStyle(fontSize: 64),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'No focus sessions yet',
|
||||
style: AppTextStyles.headline,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Start your first session\nto see your progress here!',
|
||||
style: AppTextStyles.helperText,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Start Focusing'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTodaySummary(int totalMins, int distractions, int completed) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'📅 Today',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.success.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'$completed ${completed == 1 ? 'session' : 'sessions'}',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.success,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildStat('Total', '$totalMins mins', '⏱️'),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: _buildStat(
|
||||
'Distractions',
|
||||
'$distractions ${distractions == 1 ? 'time' : 'times'}',
|
||||
'🤚',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStat(String label, String value, String emoji) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
emoji,
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDateSection(DateTime date, List<FocusSession> sessions) {
|
||||
final isToday = _isToday(date);
|
||||
final dateLabel = isToday
|
||||
? 'Today'
|
||||
: DateFormat('EEE, MMM d').format(date);
|
||||
|
||||
final totalMinutes = sessions.fold<int>(
|
||||
0,
|
||||
(sum, session) => sum + session.actualMinutes,
|
||||
);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Date header
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
dateLabel,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'($totalMinutes mins)',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Session cards
|
||||
...sessions.map((session) => _buildSessionCard(session)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSessionCard(FocusSession session) {
|
||||
final timeStr = DateFormat('HH:mm').format(session.startTime);
|
||||
final statusEmoji = session.completed ? '✅' : '⏸️';
|
||||
final statusText = session.completed ? 'Completed' : 'Stopped early';
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.divider,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Time
|
||||
Text(
|
||||
timeStr,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Duration
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${session.actualMinutes} ${session.actualMinutes == 1 ? 'minute' : 'minutes'}',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
if (session.distractionCount > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
'🤚 ${session.distractionCount} ${session.distractionCount == 1 ? 'distraction' : 'distractions'}',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Status badge
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: session.completed
|
||||
? AppColors.success.withValues(alpha: 0.1)
|
||||
: AppColors.distractionButton,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'$statusEmoji $statusText',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: session.completed
|
||||
? AppColors.success
|
||||
: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _isToday(DateTime date) {
|
||||
final now = DateTime.now();
|
||||
return date.year == now.year &&
|
||||
date.month == now.month &&
|
||||
date.day == now.day;
|
||||
}
|
||||
}
|
||||
161
lib/screens/home_screen.dart
Normal file
161
lib/screens/home_screen.dart
Normal file
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_text_styles.dart';
|
||||
import '../services/encouragement_service.dart';
|
||||
import 'focus_screen.dart';
|
||||
import 'history_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
|
||||
/// Home Screen - Loads default duration from settings
|
||||
class HomeScreen extends StatefulWidget {
|
||||
final EncouragementService encouragementService;
|
||||
|
||||
const HomeScreen({
|
||||
super.key,
|
||||
required this.encouragementService,
|
||||
});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
int _defaultDuration = 25;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadDefaultDuration();
|
||||
}
|
||||
|
||||
Future<void> _loadDefaultDuration() async {
|
||||
final duration = await SettingsScreen.getDefaultDuration();
|
||||
setState(() {
|
||||
_defaultDuration = duration;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// App Title
|
||||
Text(
|
||||
'FocusBuddy',
|
||||
style: AppTextStyles.appTitle,
|
||||
),
|
||||
|
||||
const SizedBox(height: 60),
|
||||
|
||||
// Duration Display
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
vertical: 16,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Text(
|
||||
'$_defaultDuration minutes',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 60),
|
||||
|
||||
// Start Focusing Button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => FocusScreen(
|
||||
durationMinutes: _defaultDuration,
|
||||
encouragementService: widget.encouragementService,
|
||||
),
|
||||
),
|
||||
);
|
||||
// Reload duration when returning
|
||||
if (result == true || mounted) {
|
||||
_loadDefaultDuration();
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text('Start Focusing'),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.play_arrow,
|
||||
color: AppColors.white,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Helper Text
|
||||
Text(
|
||||
"Tap 'I got distracted'\nanytime — no guilt.",
|
||||
style: AppTextStyles.helperText,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// Bottom Navigation (simplified for MVP)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const HistoryScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.bar_chart),
|
||||
label: const Text('History'),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SettingsScreen(),
|
||||
),
|
||||
);
|
||||
// Reload duration after settings
|
||||
_loadDefaultDuration();
|
||||
},
|
||||
icon: const Icon(Icons.settings),
|
||||
label: const Text('Settings'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
321
lib/screens/settings_screen.dart
Normal file
321
lib/screens/settings_screen.dart
Normal file
@@ -0,0 +1,321 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_text_styles.dart';
|
||||
|
||||
/// Settings Screen - MVP version with duration presets
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
/// Get the saved default duration (for use in other screens)
|
||||
static Future<int> getDefaultDuration() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getInt(_durationKey) ?? 25;
|
||||
}
|
||||
|
||||
static const String _durationKey = 'default_duration';
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
int _selectedDuration = 25; // Default
|
||||
|
||||
final List<int> _durationOptions = [15, 25, 45];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadSavedDuration();
|
||||
}
|
||||
|
||||
Future<void> _loadSavedDuration() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
setState(() {
|
||||
_selectedDuration = prefs.getInt(SettingsScreen._durationKey) ?? 25;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _saveDuration(int duration) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(SettingsScreen._durationKey, duration);
|
||||
setState(() {
|
||||
_selectedDuration = duration;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
title: const Text('Settings'),
|
||||
backgroundColor: AppColors.background,
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
children: [
|
||||
// Focus Duration Section
|
||||
_buildSection(
|
||||
title: 'Focus Settings',
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Text(
|
||||
'Default Focus Duration',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
),
|
||||
..._durationOptions.map((duration) {
|
||||
return _buildDurationOption(duration);
|
||||
}),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// About Section
|
||||
_buildSection(
|
||||
title: 'About',
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
'Privacy Policy',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
trailing: const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 16,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
onTap: () {
|
||||
_showPrivacyPolicy();
|
||||
},
|
||||
),
|
||||
const Divider(color: AppColors.divider),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
'About FocusBuddy',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
trailing: const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 16,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
onTap: () {
|
||||
_showAboutDialog();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// Version info
|
||||
Center(
|
||||
child: Text(
|
||||
'Version 1.0.0 (MVP)',
|
||||
style: AppTextStyles.helperText.copyWith(fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSection({
|
||||
required String title,
|
||||
required List<Widget> children,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
...children,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDurationOption(int duration) {
|
||||
final isSelected = _selectedDuration == duration;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _saveDuration(duration),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColors.primary.withValues(alpha: 0.1)
|
||||
: AppColors.background,
|
||||
border: Border.all(
|
||||
color: isSelected ? AppColors.primary : AppColors.divider,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Radio button
|
||||
Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: isSelected ? AppColors.primary : AppColors.textSecondary,
|
||||
width: 2,
|
||||
),
|
||||
color: isSelected ? AppColors.primary : Colors.transparent,
|
||||
),
|
||||
child: isSelected
|
||||
? const Center(
|
||||
child: Icon(
|
||||
Icons.check,
|
||||
size: 12,
|
||||
color: AppColors.white,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Duration text
|
||||
Expanded(
|
||||
child: Text(
|
||||
'$duration minutes',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 16,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
color: isSelected
|
||||
? AppColors.primary
|
||||
: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Description
|
||||
if (duration == 25)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.success.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Text(
|
||||
'Default',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.success,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showPrivacyPolicy() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Privacy Policy'),
|
||||
content: SingleChildScrollView(
|
||||
child: Text(
|
||||
'FocusBuddy is 100% offline. We do not collect your name, email, '
|
||||
'location, or usage data. All sessions stay on your device.\n\n'
|
||||
'There is no cloud sync, no account system, and no analytics tracking.\n\n'
|
||||
'For the full privacy policy, visit:\n'
|
||||
'[Your website URL]/privacy',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAboutDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('About FocusBuddy'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'FocusBuddy',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'A gentle focus timer for neurodivergent minds',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'"Focus is not about never getting distracted — '
|
||||
'it\'s about gently coming back every time you do."',
|
||||
style: AppTextStyles.encouragementQuote,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'✨ No punishment for distractions\n'
|
||||
'💚 Encouragement over criticism\n'
|
||||
'🔒 100% offline and private\n'
|
||||
'🌱 Made with care',
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user