first commit
This commit is contained in:
43
lib/main.dart
Normal file
43
lib/main.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'theme/app_theme.dart';
|
||||
import 'services/storage_service.dart';
|
||||
import 'services/encouragement_service.dart';
|
||||
import 'services/notification_service.dart';
|
||||
import 'screens/home_screen.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Initialize services
|
||||
await StorageService.init();
|
||||
|
||||
final encouragementService = EncouragementService();
|
||||
await encouragementService.loadMessages();
|
||||
|
||||
// Initialize notification service
|
||||
final notificationService = NotificationService();
|
||||
await notificationService.initialize();
|
||||
// Request permissions on first launch
|
||||
await notificationService.requestPermissions();
|
||||
|
||||
runApp(MyApp(encouragementService: encouragementService));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
final EncouragementService encouragementService;
|
||||
|
||||
const MyApp({
|
||||
super.key,
|
||||
required this.encouragementService,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'FocusBuddy',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.lightTheme,
|
||||
home: HomeScreen(encouragementService: encouragementService),
|
||||
);
|
||||
}
|
||||
}
|
||||
47
lib/models/distraction_type.dart
Normal file
47
lib/models/distraction_type.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
/// Predefined distraction types
|
||||
class DistractionType {
|
||||
static const scrollingSocialMedia = 'scrolling_social_media';
|
||||
static const gotInterrupted = 'got_interrupted';
|
||||
static const feltOverwhelmed = 'felt_overwhelmed';
|
||||
static const justZonedOut = 'just_zoned_out';
|
||||
|
||||
/// Get display name for a distraction type
|
||||
static String getDisplayName(String type) {
|
||||
switch (type) {
|
||||
case scrollingSocialMedia:
|
||||
return 'Scrolling social media';
|
||||
case gotInterrupted:
|
||||
return 'Got interrupted';
|
||||
case feltOverwhelmed:
|
||||
return 'Felt overwhelmed';
|
||||
case justZonedOut:
|
||||
return 'Just zoned out';
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
/// Get emoji for a distraction type
|
||||
static String getEmoji(String type) {
|
||||
switch (type) {
|
||||
case scrollingSocialMedia:
|
||||
return '📱';
|
||||
case gotInterrupted:
|
||||
return '👥';
|
||||
case feltOverwhelmed:
|
||||
return '😰';
|
||||
case justZonedOut:
|
||||
return '💭';
|
||||
default:
|
||||
return '❓';
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all distraction types
|
||||
static List<String> get all => [
|
||||
scrollingSocialMedia,
|
||||
gotInterrupted,
|
||||
feltOverwhelmed,
|
||||
justZonedOut,
|
||||
];
|
||||
}
|
||||
44
lib/models/focus_session.dart
Normal file
44
lib/models/focus_session.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'focus_session.g.dart';
|
||||
|
||||
@HiveType(typeId: 0)
|
||||
class FocusSession extends HiveObject {
|
||||
@HiveField(0)
|
||||
DateTime startTime;
|
||||
|
||||
@HiveField(1)
|
||||
int durationMinutes; // Planned duration (e.g., 25)
|
||||
|
||||
@HiveField(2)
|
||||
int actualMinutes; // Actual time focused (may be less if stopped early)
|
||||
|
||||
@HiveField(3)
|
||||
int distractionCount; // Simplified: just count distractions
|
||||
|
||||
@HiveField(4)
|
||||
bool completed; // Whether the session was completed or stopped early
|
||||
|
||||
@HiveField(5)
|
||||
List<String> distractionTypes; // List of distraction type strings
|
||||
|
||||
FocusSession({
|
||||
required this.startTime,
|
||||
required this.durationMinutes,
|
||||
required this.actualMinutes,
|
||||
this.distractionCount = 0,
|
||||
this.completed = false,
|
||||
List<String>? distractionTypes,
|
||||
}) : distractionTypes = distractionTypes ?? [];
|
||||
|
||||
/// Get the date (without time) for grouping sessions by day
|
||||
DateTime get date => DateTime(startTime.year, startTime.month, startTime.day);
|
||||
|
||||
/// Check if this session was today
|
||||
bool get isToday {
|
||||
final now = DateTime.now();
|
||||
return date.year == now.year &&
|
||||
date.month == now.month &&
|
||||
date.day == now.day;
|
||||
}
|
||||
}
|
||||
56
lib/models/focus_session.g.dart
Normal file
56
lib/models/focus_session.g.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'focus_session.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class FocusSessionAdapter extends TypeAdapter<FocusSession> {
|
||||
@override
|
||||
final int typeId = 0;
|
||||
|
||||
@override
|
||||
FocusSession read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return FocusSession(
|
||||
startTime: fields[0] as DateTime,
|
||||
durationMinutes: fields[1] as int,
|
||||
actualMinutes: fields[2] as int,
|
||||
distractionCount: fields[3] as int,
|
||||
completed: fields[4] as bool,
|
||||
distractionTypes: (fields[5] as List?)?.cast<String>(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, FocusSession obj) {
|
||||
writer
|
||||
..writeByte(6)
|
||||
..writeByte(0)
|
||||
..write(obj.startTime)
|
||||
..writeByte(1)
|
||||
..write(obj.durationMinutes)
|
||||
..writeByte(2)
|
||||
..write(obj.actualMinutes)
|
||||
..writeByte(3)
|
||||
..write(obj.distractionCount)
|
||||
..writeByte(4)
|
||||
..write(obj.completed)
|
||||
..writeByte(5)
|
||||
..write(obj.distractionTypes);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is FocusSessionAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
39
lib/services/encouragement_service.dart
Normal file
39
lib/services/encouragement_service.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Service to manage encouragement messages
|
||||
class EncouragementService {
|
||||
List<String> _messages = [];
|
||||
final Random _random = Random();
|
||||
|
||||
/// Load encouragement messages from assets
|
||||
Future<void> loadMessages() async {
|
||||
try {
|
||||
final String jsonString =
|
||||
await rootBundle.loadString('assets/encouragements.json');
|
||||
final List<dynamic> jsonList = json.decode(jsonString);
|
||||
_messages = jsonList.cast<String>();
|
||||
} catch (e) {
|
||||
// Fallback messages if file can't be loaded
|
||||
_messages = [
|
||||
"Showing up is half the battle.",
|
||||
"Every minute counts.",
|
||||
"You're learning, not failing.",
|
||||
"Gentleness is strength.",
|
||||
"Progress over perfection.",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a random encouragement message
|
||||
String getRandomMessage() {
|
||||
if (_messages.isEmpty) {
|
||||
return "You're doing great!";
|
||||
}
|
||||
return _messages[_random.nextInt(_messages.length)];
|
||||
}
|
||||
|
||||
/// Get all messages (for testing)
|
||||
List<String> getAllMessages() => List.from(_messages);
|
||||
}
|
||||
194
lib/services/notification_service.dart
Normal file
194
lib/services/notification_service.dart
Normal file
@@ -0,0 +1,194 @@
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// Notification Service - Handles local notifications
|
||||
class NotificationService {
|
||||
static final NotificationService _instance = NotificationService._internal();
|
||||
factory NotificationService() => _instance;
|
||||
NotificationService._internal();
|
||||
|
||||
final FlutterLocalNotificationsPlugin _notifications =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
bool _initialized = false;
|
||||
|
||||
/// Initialize notification service
|
||||
Future<void> initialize() async {
|
||||
if (_initialized) return;
|
||||
|
||||
// Skip initialization on web platform
|
||||
if (kIsWeb) {
|
||||
if (kDebugMode) {
|
||||
print('Notifications not supported on web platform');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Android initialization settings
|
||||
const androidSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
|
||||
|
||||
// iOS initialization settings
|
||||
const iosSettings = DarwinInitializationSettings(
|
||||
requestAlertPermission: true,
|
||||
requestBadgePermission: true,
|
||||
requestSoundPermission: true,
|
||||
);
|
||||
|
||||
const initSettings = InitializationSettings(
|
||||
android: androidSettings,
|
||||
iOS: iosSettings,
|
||||
);
|
||||
|
||||
await _notifications.initialize(
|
||||
initSettings,
|
||||
onDidReceiveNotificationResponse: _onNotificationTapped,
|
||||
);
|
||||
|
||||
_initialized = true;
|
||||
if (kDebugMode) {
|
||||
print('Notification service initialized successfully');
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to initialize notifications: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle notification tap
|
||||
void _onNotificationTapped(NotificationResponse response) {
|
||||
if (kDebugMode) {
|
||||
print('Notification tapped: ${response.payload}');
|
||||
}
|
||||
// TODO: Navigate to appropriate screen if needed
|
||||
}
|
||||
|
||||
/// Request notification permissions (iOS only, Android auto-grants)
|
||||
Future<bool> requestPermissions() async {
|
||||
if (kIsWeb) return false;
|
||||
|
||||
try {
|
||||
final result = await _notifications
|
||||
.resolvePlatformSpecificImplementation<
|
||||
IOSFlutterLocalNotificationsPlugin>()
|
||||
?.requestPermissions(
|
||||
alert: true,
|
||||
badge: true,
|
||||
sound: true,
|
||||
);
|
||||
|
||||
return result ?? true; // Android always returns true
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to request permissions: $e');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Show focus session completed notification
|
||||
Future<void> showFocusCompletedNotification({
|
||||
required int minutes,
|
||||
required int distractionCount,
|
||||
}) async {
|
||||
if (kIsWeb || !_initialized) return;
|
||||
|
||||
try {
|
||||
const androidDetails = AndroidNotificationDetails(
|
||||
'focus_completed',
|
||||
'Focus Session Completed',
|
||||
channelDescription: 'Notifications for completed focus sessions',
|
||||
importance: Importance.high,
|
||||
priority: Priority.high,
|
||||
enableVibration: true,
|
||||
playSound: true,
|
||||
);
|
||||
|
||||
const iosDetails = DarwinNotificationDetails(
|
||||
presentAlert: true,
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
);
|
||||
|
||||
const notificationDetails = NotificationDetails(
|
||||
android: androidDetails,
|
||||
iOS: iosDetails,
|
||||
);
|
||||
|
||||
// Create notification message
|
||||
final title = '🎉 Focus session complete!';
|
||||
final body = distractionCount == 0
|
||||
? 'You focused for $minutes ${minutes == 1 ? 'minute' : 'minutes'} without distractions!'
|
||||
: 'You focused for $minutes ${minutes == 1 ? 'minute' : 'minutes'}. Great effort!';
|
||||
|
||||
await _notifications.show(
|
||||
0, // Notification ID
|
||||
title,
|
||||
body,
|
||||
notificationDetails,
|
||||
payload: 'focus_completed',
|
||||
);
|
||||
|
||||
if (kDebugMode) {
|
||||
print('Notification shown: $title - $body');
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to show notification: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Show reminder notification (optional feature for future)
|
||||
Future<void> showReminderNotification({
|
||||
required String message,
|
||||
}) async {
|
||||
if (kIsWeb || !_initialized) return;
|
||||
|
||||
try {
|
||||
const androidDetails = AndroidNotificationDetails(
|
||||
'reminders',
|
||||
'Focus Reminders',
|
||||
channelDescription: 'Gentle reminders to focus',
|
||||
importance: Importance.defaultImportance,
|
||||
priority: Priority.defaultPriority,
|
||||
);
|
||||
|
||||
const iosDetails = DarwinNotificationDetails();
|
||||
|
||||
const notificationDetails = NotificationDetails(
|
||||
android: androidDetails,
|
||||
iOS: iosDetails,
|
||||
);
|
||||
|
||||
await _notifications.show(
|
||||
1, // Different ID from completion notifications
|
||||
'💚 FocusBuddy',
|
||||
message,
|
||||
notificationDetails,
|
||||
payload: 'reminder',
|
||||
);
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to show reminder: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Cancel all notifications
|
||||
Future<void> cancelAll() async {
|
||||
if (kIsWeb || !_initialized) return;
|
||||
|
||||
try {
|
||||
await _notifications.cancelAll();
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to cancel notifications: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if notifications are supported on this platform
|
||||
bool get isSupported => !kIsWeb;
|
||||
}
|
||||
80
lib/services/storage_service.dart
Normal file
80
lib/services/storage_service.dart
Normal file
@@ -0,0 +1,80 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import '../models/focus_session.dart';
|
||||
|
||||
/// Service to manage local storage using Hive
|
||||
class StorageService {
|
||||
static const String _focusSessionBox = 'focus_sessions';
|
||||
|
||||
/// Initialize Hive
|
||||
static Future<void> init() async {
|
||||
await Hive.initFlutter();
|
||||
|
||||
// Register adapters
|
||||
Hive.registerAdapter(FocusSessionAdapter());
|
||||
|
||||
// Open boxes
|
||||
await Hive.openBox<FocusSession>(_focusSessionBox);
|
||||
}
|
||||
|
||||
/// Get the focus sessions box
|
||||
Box<FocusSession> get _sessionsBox => Hive.box<FocusSession>(_focusSessionBox);
|
||||
|
||||
/// Save a focus session
|
||||
Future<void> saveFocusSession(FocusSession session) async {
|
||||
await _sessionsBox.add(session);
|
||||
}
|
||||
|
||||
/// Get all focus sessions
|
||||
List<FocusSession> getAllSessions() {
|
||||
return _sessionsBox.values.toList();
|
||||
}
|
||||
|
||||
/// Get today's focus sessions
|
||||
List<FocusSession> getTodaySessions() {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
|
||||
return _sessionsBox.values.where((session) {
|
||||
final sessionDate = DateTime(
|
||||
session.startTime.year,
|
||||
session.startTime.month,
|
||||
session.startTime.day,
|
||||
);
|
||||
return sessionDate == today;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// Get total focus minutes for today
|
||||
int getTodayTotalMinutes() {
|
||||
return getTodaySessions()
|
||||
.fold<int>(0, (sum, session) => sum + session.actualMinutes);
|
||||
}
|
||||
|
||||
/// Get total distractions for today
|
||||
int getTodayDistractionCount() {
|
||||
return getTodaySessions()
|
||||
.fold<int>(0, (sum, session) => sum + session.distractionCount);
|
||||
}
|
||||
|
||||
/// Get total completed sessions for today
|
||||
int getTodayCompletedCount() {
|
||||
return getTodaySessions()
|
||||
.where((session) => session.completed)
|
||||
.length;
|
||||
}
|
||||
|
||||
/// Delete a focus session
|
||||
Future<void> deleteSession(FocusSession session) async {
|
||||
await session.delete();
|
||||
}
|
||||
|
||||
/// Clear all sessions (for testing/debugging)
|
||||
Future<void> clearAllSessions() async {
|
||||
await _sessionsBox.clear();
|
||||
}
|
||||
|
||||
/// Close all boxes
|
||||
static Future<void> close() async {
|
||||
await Hive.close();
|
||||
}
|
||||
}
|
||||
24
lib/theme/app_colors.dart
Normal file
24
lib/theme/app_colors.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// App color palette following the design spec
|
||||
/// Based on Morandi color system - calm and gentle
|
||||
class AppColors {
|
||||
// Primary colors
|
||||
static const primary = Color(0xFFA7C4BC); // Calm Green
|
||||
static const background = Color(0xFFF8F6F2); // Warm off-white
|
||||
|
||||
// Text colors
|
||||
static const textPrimary = Color(0xFF5B6D6D);
|
||||
static const textSecondary = Color(0xFF8A9B9B);
|
||||
|
||||
// Button colors
|
||||
static const distractionButton = Color(0xFFE0E0E0);
|
||||
static const success = Color(0xFF88C9A1);
|
||||
|
||||
// Additional colors
|
||||
static const white = Color(0xFFFFFFFF);
|
||||
static const divider = Color(0xFFF0F0F0);
|
||||
|
||||
// Prevent instantiation
|
||||
AppColors._();
|
||||
}
|
||||
68
lib/theme/app_text_styles.dart
Normal file
68
lib/theme/app_text_styles.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'app_colors.dart';
|
||||
|
||||
/// Typography styles following the design spec
|
||||
/// Uses Nunito font family from Google Fonts
|
||||
class AppTextStyles {
|
||||
// App Title
|
||||
static final appTitle = GoogleFonts.nunito(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700, // Bold
|
||||
color: AppColors.textPrimary,
|
||||
);
|
||||
|
||||
// Timer Display
|
||||
static final timerDisplay = GoogleFonts.nunito(
|
||||
fontSize: 64,
|
||||
fontWeight: FontWeight.w800, // ExtraBold
|
||||
letterSpacing: 2,
|
||||
color: AppColors.textPrimary,
|
||||
);
|
||||
|
||||
// Button Text
|
||||
static final buttonText = GoogleFonts.nunito(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600, // SemiBold
|
||||
color: AppColors.white,
|
||||
);
|
||||
|
||||
// Body Text
|
||||
static final bodyText = GoogleFonts.nunito(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400, // Regular
|
||||
color: AppColors.textPrimary,
|
||||
);
|
||||
|
||||
// Helper Text
|
||||
static final helperText = GoogleFonts.nunito(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300, // Light
|
||||
color: AppColors.textSecondary,
|
||||
);
|
||||
|
||||
// Headline
|
||||
static final headline = GoogleFonts.nunito(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600, // SemiBold
|
||||
color: AppColors.textPrimary,
|
||||
);
|
||||
|
||||
// Large number (for focus minutes display)
|
||||
static final largeNumber = GoogleFonts.nunito(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w700, // Bold
|
||||
color: AppColors.textPrimary,
|
||||
);
|
||||
|
||||
// Encouragement quote (italic)
|
||||
static final encouragementQuote = GoogleFonts.nunito(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: AppColors.textSecondary,
|
||||
);
|
||||
|
||||
// Prevent instantiation
|
||||
AppTextStyles._();
|
||||
}
|
||||
69
lib/theme/app_theme.dart
Normal file
69
lib/theme/app_theme.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'app_colors.dart';
|
||||
import 'app_text_styles.dart';
|
||||
|
||||
/// App theme configuration
|
||||
class AppTheme {
|
||||
static ThemeData get lightTheme {
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
|
||||
// Color scheme
|
||||
colorScheme: ColorScheme.light(
|
||||
primary: AppColors.primary,
|
||||
surface: AppColors.background,
|
||||
onPrimary: AppColors.white,
|
||||
onSurface: AppColors.textPrimary,
|
||||
),
|
||||
|
||||
// Scaffold
|
||||
scaffoldBackgroundColor: AppColors.background,
|
||||
|
||||
// AppBar
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: AppColors.background,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
titleTextStyle: AppTextStyles.appTitle,
|
||||
iconTheme: const IconThemeData(color: AppColors.textPrimary),
|
||||
),
|
||||
|
||||
// Elevated Button
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: AppColors.white,
|
||||
minimumSize: const Size(double.infinity, 56),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
elevation: 4,
|
||||
textStyle: AppTextStyles.buttonText,
|
||||
),
|
||||
),
|
||||
|
||||
// Text Button
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.textSecondary,
|
||||
textStyle: AppTextStyles.bodyText,
|
||||
),
|
||||
),
|
||||
|
||||
// Default text theme - Use Google Fonts
|
||||
textTheme: GoogleFonts.nunitoTextTheme(
|
||||
TextTheme(
|
||||
displayLarge: AppTextStyles.timerDisplay,
|
||||
headlineMedium: AppTextStyles.headline,
|
||||
bodyLarge: AppTextStyles.bodyText,
|
||||
bodyMedium: AppTextStyles.helperText,
|
||||
labelLarge: AppTextStyles.buttonText,
|
||||
),
|
||||
),
|
||||
|
||||
// Font family - Use Google Fonts
|
||||
fontFamily: GoogleFonts.nunito().fontFamily,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user