mirror of
https://github.com/Dvorinka/1356.git
synced 2026-06-05 04:22:55 +00:00
feat: Complete Phase 1 - Full Flutter app implementation with comprehensive features
Version: 1.1.0 Major changes: - Implemented complete Flutter app structure with all core features - Added comprehensive UI screens for auth, countdown, goals, profile, settings, and social features - Integrated Supabase backend with authentication and data repositories - Added offline support with Hive caching and local storage - Implemented comprehensive routing with go_router - Added location services with Google Maps integration - Implemented notifications and home widget support - Added voice recording capabilities and AI chat features - Created comprehensive test suite and documentation - Added Android and iOS platform configurations - Implemented achievements system and social features - Added calendar integration and bucket list functionality This represents a complete Phase 1 milestone with 3,775 additions across 31 files.
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'dart:async';
|
||||
import '../../../data/models/user_model.dart';
|
||||
import '../../../data/repositories/countdown_repository.dart';
|
||||
import '../../../bootstrap/supabase_client.dart';
|
||||
import '../../../core/services/analytics_service.dart';
|
||||
import '../../../core/utils/date_time_utils.dart';
|
||||
import '../../../data/services/home_screen_widget_service.dart';
|
||||
import '../../auth/application/auth_controller.dart';
|
||||
|
||||
class CountdownController extends StateNotifier<CountdownState> {
|
||||
final CountdownRepository _repository;
|
||||
final String _userId;
|
||||
final AnalyticsService _analytics = AnalyticsService();
|
||||
Timer? _timer;
|
||||
DateTime? _lastUpdateTime;
|
||||
final HomeScreenWidgetService _widgetService = HomeScreenWidgetService();
|
||||
|
||||
CountdownController(this._repository, this._userId) : super(const CountdownState.initial()) {
|
||||
_loadCountdown();
|
||||
_startTimer();
|
||||
}
|
||||
|
||||
void _loadCountdown() async {
|
||||
state = const CountdownState.loading();
|
||||
try {
|
||||
final user = await _repository.getCountdownInfo(_userId);
|
||||
state = CountdownState.loaded(user);
|
||||
_analytics.logCountdownViewed();
|
||||
await _updateHomeScreenWidget(user);
|
||||
} catch (e) {
|
||||
state = CountdownState.error(e.toString());
|
||||
_analytics.logError(error: e.toString(), context: 'loadCountdown');
|
||||
}
|
||||
}
|
||||
|
||||
void loadCountdown() {
|
||||
_loadCountdown();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (state is CountdownLoaded) {
|
||||
final loadedState = state as CountdownLoaded;
|
||||
final now = DateTime.now();
|
||||
|
||||
// Only update state if the seconds have actually changed
|
||||
if (_lastUpdateTime == null ||
|
||||
_lastUpdateTime!.second != now.second ||
|
||||
_lastUpdateTime!.minute != now.minute) {
|
||||
final user = loadedState.user;
|
||||
final countdownEnd = user?.countdownEndDate;
|
||||
|
||||
if (countdownEnd != null) {
|
||||
final remaining = countdownEnd.difference(now);
|
||||
|
||||
if (remaining.isNegative) {
|
||||
state = CountdownState.completed(user);
|
||||
_timer?.cancel();
|
||||
}
|
||||
}
|
||||
_lastUpdateTime = now;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> startCountdown() async {
|
||||
try {
|
||||
final user = await _repository.startCountdown(_userId);
|
||||
_analytics.logCountdownStarted(
|
||||
startDate: user.countdownStartDate!.toIso8601String(),
|
||||
endDate: user.countdownEndDate!.toIso8601String(),
|
||||
);
|
||||
state = CountdownState.loaded(user);
|
||||
await _updateHomeScreenWidget(user);
|
||||
} catch (e) {
|
||||
state = CountdownState.error(e.toString());
|
||||
_analytics.logError(error: e.toString(), context: 'startCountdown');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _updateHomeScreenWidget(User? user) async {
|
||||
try {
|
||||
if (user == null || user.countdownEndDate == null) {
|
||||
await _widgetService.updateNextCountdownWidget(
|
||||
title: '1356-day challenge',
|
||||
timeLeft: 'Not started',
|
||||
subtitle: 'Open Lifetimer to begin your journey',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final endDate = user.countdownEndDate!;
|
||||
final now = DateTime.now();
|
||||
final remaining = endDate.difference(now);
|
||||
|
||||
if (remaining.isNegative) {
|
||||
await _widgetService.updateNextCountdownWidget(
|
||||
title: '1356-day challenge',
|
||||
timeLeft: 'Completed',
|
||||
subtitle: 'Open Lifetimer to review your journey',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final compact = DateTimeUtils.formatCountdownCompact(remaining);
|
||||
final subtitle = 'Ends on ${DateTimeUtils.formatDate(endDate)}';
|
||||
|
||||
await _widgetService.updateNextCountdownWidget(
|
||||
title: '1356-day challenge',
|
||||
timeLeft: compact,
|
||||
subtitle: subtitle,
|
||||
);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class CountdownState {
|
||||
final bool isLoading;
|
||||
final User? user;
|
||||
final String? error;
|
||||
|
||||
const CountdownState({
|
||||
this.isLoading = false,
|
||||
this.user,
|
||||
this.error,
|
||||
});
|
||||
|
||||
const CountdownState.initial() : isLoading = false, user = null, error = null;
|
||||
|
||||
const CountdownState.loading() : isLoading = true, user = null, error = null;
|
||||
|
||||
const CountdownState.loaded(this.user) : isLoading = false, error = null;
|
||||
|
||||
const CountdownState.completed(this.user) : isLoading = false, error = null;
|
||||
|
||||
const CountdownState.error(this.error) : isLoading = false, user = null;
|
||||
}
|
||||
|
||||
class CountdownLoaded extends CountdownState {
|
||||
const CountdownLoaded(User user) : super(user: user);
|
||||
}
|
||||
|
||||
final countdownRepositoryProvider = Provider<CountdownRepository>((ref) {
|
||||
return CountdownRepository(supabaseClient);
|
||||
});
|
||||
|
||||
final countdownControllerProvider = StateNotifierProvider<CountdownController, CountdownState>((ref) {
|
||||
final repository = ref.watch(countdownRepositoryProvider);
|
||||
final authController = ref.read(authControllerProvider.notifier);
|
||||
final userId = authController.currentUserId ?? '';
|
||||
|
||||
if (userId.isEmpty) {
|
||||
return CountdownController(repository, 'placeholder_user_id');
|
||||
}
|
||||
|
||||
return CountdownController(repository, userId);
|
||||
});
|
||||
@@ -0,0 +1,204 @@
|
||||
// ignore_for_file: deprecated_member_use
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/widgets/app_scaffold.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../goals/application/goals_controller.dart';
|
||||
import '../application/countdown_controller.dart';
|
||||
import 'countdown_start_confirmation_dialog.dart';
|
||||
|
||||
class BucketListConfirmationScreen extends ConsumerWidget {
|
||||
const BucketListConfirmationScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final goalsState = ref.watch(goalsControllerProvider);
|
||||
|
||||
if (goalsState.isLoading) {
|
||||
return const AppScaffold(
|
||||
title: 'Confirm Your Bucket List',
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (goalsState.error != null) {
|
||||
return AppScaffold(
|
||||
title: 'Confirm Your Bucket List',
|
||||
body: Center(
|
||||
child: Text('Error: ${goalsState.error}'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final goals = goalsState.goals;
|
||||
|
||||
if (goals.isEmpty) {
|
||||
return const AppScaffold(
|
||||
title: 'Confirm Your Bucket List',
|
||||
body: Center(
|
||||
child: Text('No goals in your bucket list'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AppScaffold(
|
||||
title: 'Confirm Your Bucket List',
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
itemCount: goals.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.checklist_rounded,
|
||||
size: 64,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Your Bucket List',
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'${goals.length} goal${goals.length != 1 ? 's' : ''} ready',
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Divider(),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
final goal = goals[index - 1];
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12.0),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: goal.completed
|
||||
? Theme.of(context).colorScheme.primaryContainer
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: Icon(
|
||||
goal.completed ? Icons.check : Icons.flag_outlined,
|
||||
color: goal.completed
|
||||
? Theme.of(context).colorScheme.onPrimaryContainer
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
goal.title,
|
||||
style: TextStyle(
|
||||
decoration: goal.completed ? TextDecoration.lineThrough : null,
|
||||
),
|
||||
),
|
||||
subtitle: goal.description != null && goal.description!.isNotEmpty
|
||||
? Text(
|
||||
goal.description!,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)
|
||||
: null,
|
||||
trailing: goal.progress > 0
|
||||
? Text('${goal.progress}%')
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).shadowColor.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.tertiaryContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
color: Theme.of(context).colorScheme.onTertiaryContainer,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Review your goals carefully. Once confirmed, you cannot make changes.',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onTertiaryContainer,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: const Text('Edit Goals'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PrimaryButton(
|
||||
onPressed: () async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CountdownStartConfirmationDialog(
|
||||
goalCount: goals.length,
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && context.mounted) {
|
||||
ref.read(countdownControllerProvider.notifier).loadCountdown();
|
||||
if (context.mounted) {
|
||||
context.go('/home');
|
||||
}
|
||||
}
|
||||
},
|
||||
text: 'Confirm & Start',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../application/countdown_controller.dart';
|
||||
|
||||
class CountdownStartConfirmationDialog extends ConsumerWidget {
|
||||
final int goalCount;
|
||||
|
||||
const CountdownStartConfirmationDialog({
|
||||
super.key,
|
||||
required this.goalCount,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return AlertDialog(
|
||||
title: const Text('Start Your 1356-Day Journey'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.timer_outlined,
|
||||
size: 48,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'You have $goalCount goal${goalCount != 1 ? 's' : ''} in your bucket list.',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Once you start the countdown:',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildWarningItem(
|
||||
context,
|
||||
Icons.lock_outline,
|
||||
'The countdown cannot be paused, stopped, or reset',
|
||||
),
|
||||
_buildWarningItem(
|
||||
context,
|
||||
Icons.edit_off_outlined,
|
||||
'You will not be able to add, remove, or edit goals',
|
||||
),
|
||||
_buildWarningItem(
|
||||
context,
|
||||
Icons.timer_off_outlined,
|
||||
'The 1356 days will run continuously until completion',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.errorContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'This action is irreversible. Make sure you are ready to commit.',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onErrorContainer,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
PrimaryButton(
|
||||
onPressed: () async {
|
||||
try {
|
||||
await ref.read(countdownControllerProvider.notifier).startCountdown();
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to start countdown: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
text: 'Start Countdown',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWarningItem(BuildContext context, IconData icon, String text) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,123 @@
|
||||
import 'package:flutter/material.dart';
|
||||
// ignore_for_file: deprecated_member_use
|
||||
|
||||
class HomeCountdownScreen extends StatelessWidget {
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../core/widgets/app_scaffold.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../core/widgets/loading_indicator.dart';
|
||||
import '../../../data/models/user_model.dart';
|
||||
import '../application/countdown_controller.dart';
|
||||
import '../../achievements/application/achievements_controller.dart';
|
||||
|
||||
class HomeCountdownScreen extends ConsumerStatefulWidget {
|
||||
const HomeCountdownScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<HomeCountdownScreen> createState() => _HomeCountdownScreenState();
|
||||
}
|
||||
|
||||
class _HomeCountdownScreenState extends ConsumerState<HomeCountdownScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('LifeTimer'),
|
||||
final countdownState = ref.watch(countdownControllerProvider);
|
||||
final achievementsState = ref.watch(achievementsControllerProvider);
|
||||
final int? level = achievementsState.totalCount > 0
|
||||
? achievementsState.level
|
||||
: null;
|
||||
|
||||
return AppScaffold(
|
||||
body: SafeArea(
|
||||
child: countdownState.isLoading
|
||||
? const Center(child: LoadingIndicator())
|
||||
: countdownState.error != null
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('Error: ${countdownState.error}'),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () => context.go('/'),
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: countdownState.user == null || !countdownState.user!.hasCountdownStarted
|
||||
? _CountdownNotStartedScreen()
|
||||
: _CountdownActiveScreen(
|
||||
user: countdownState.user!,
|
||||
level: level,
|
||||
),
|
||||
),
|
||||
body: const Center(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => context.push('/ai-chat'),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||||
child: const Icon(Icons.psychology),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CountdownNotStartedScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Semantics(
|
||||
label: 'Countdown not started screen',
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'1356',
|
||||
style: TextStyle(
|
||||
fontSize: 72,
|
||||
fontWeight: FontWeight.bold,
|
||||
Semantics(
|
||||
label: 'Timer icon',
|
||||
child: const Icon(
|
||||
Icons.timer_outlined,
|
||||
size: 100,
|
||||
color: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Text(
|
||||
'days remaining',
|
||||
style: TextStyle(fontSize: 24),
|
||||
'Ready to Start?',
|
||||
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
semanticsLabel: 'Ready to Start? Your 1356-day journey is waiting.',
|
||||
),
|
||||
SizedBox(height: 32),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Your countdown starts here',
|
||||
style: TextStyle(fontSize: 18),
|
||||
'Your 1356-day journey is waiting.\nCreate your bucket list and begin your countdown.',
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
Semantics(
|
||||
button: true,
|
||||
label: 'Create your goals button',
|
||||
hint: 'Tap to create your bucket list goals',
|
||||
child: PrimaryButton(
|
||||
onPressed: () => context.push('/goals'),
|
||||
text: 'Create Your Goals',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Semantics(
|
||||
button: true,
|
||||
label: 'View existing goals button',
|
||||
hint: 'Tap to view your existing goals',
|
||||
child: OutlinedButton(
|
||||
onPressed: () => context.push('/goals'),
|
||||
child: const Text('View Existing Goals'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -35,3 +125,521 @@ class HomeCountdownScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CountdownActiveScreen extends StatelessWidget {
|
||||
final User user;
|
||||
final int? level;
|
||||
|
||||
const _CountdownActiveScreen({required this.user, this.level});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final now = DateTime.now();
|
||||
final endDate = user.countdownEndDate!;
|
||||
final remaining = endDate.difference(now);
|
||||
|
||||
if (remaining.isNegative) {
|
||||
return _CountdownCompletedScreen(user: user, level: level);
|
||||
}
|
||||
|
||||
final days = remaining.inDays;
|
||||
final hours = remaining.inHours % 24;
|
||||
final minutes = remaining.inMinutes % 60;
|
||||
final seconds = remaining.inSeconds % 60;
|
||||
|
||||
final totalDuration = endDate.difference(user.countdownStartDate!);
|
||||
final elapsed = now.difference(user.countdownStartDate!);
|
||||
final progress = elapsed.inSeconds / totalDuration.inSeconds;
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {},
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 32),
|
||||
Text(
|
||||
'Your Journey',
|
||||
style: GoogleFonts.spaceGrotesk(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.2,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.85),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'1356-day challenge',
|
||||
style: GoogleFonts.plusJakartaSans(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
if (level != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary
|
||||
.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.star_rounded,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Level $level',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.labelMedium
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
_TodayCalendarCard(),
|
||||
const SizedBox(height: 24),
|
||||
_CountdownDisplay(
|
||||
days: days,
|
||||
hours: hours,
|
||||
minutes: minutes,
|
||||
seconds: seconds,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
_ProgressRing(progress: progress.clamp(0.0, 1.0)),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'${(progress * 100).toStringAsFixed(1)}% Complete',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
_MotivationalMessage(progress: progress),
|
||||
const SizedBox(height: 32),
|
||||
PrimaryButton(
|
||||
onPressed: () => context.push('/goals'),
|
||||
text: 'View My Goals',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => context.push('/profile'),
|
||||
icon: const Icon(Icons.person_outline),
|
||||
label: const Text('My Profile'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TodayCalendarCard extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final now = DateTime.now();
|
||||
final dayLabel = DateFormat('EEE').format(now);
|
||||
final dateLabel = DateFormat('d MMM').format(now);
|
||||
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
onTap: () => context.push('/calendar'),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.03),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary
|
||||
.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
dayLabel.toUpperCase(),
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
dateLabel,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Today\'s plan',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'Tap to view your calendar',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CountdownCompletedScreen extends StatelessWidget {
|
||||
final User user;
|
||||
final int? level;
|
||||
|
||||
const _CountdownCompletedScreen({required this.user, this.level});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.celebration,
|
||||
size: 100,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Text(
|
||||
'Journey Complete!',
|
||||
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
if (level != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary
|
||||
.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.star_rounded,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Level $level',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.labelMedium
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'You\'ve completed your 1356-day challenge.\nCongratulations on your achievement!',
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
PrimaryButton(
|
||||
onPressed: () => context.push('/goals'),
|
||||
text: 'Review Your Journey',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CountdownDisplay extends StatelessWidget {
|
||||
final int days;
|
||||
final int hours;
|
||||
final int minutes;
|
||||
final int seconds;
|
||||
|
||||
const _CountdownDisplay({
|
||||
required this.days,
|
||||
required this.hours,
|
||||
required this.minutes,
|
||||
required this.seconds,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
final heroBackground = isDark ? const Color(0xFF020617) : colorScheme.surface;
|
||||
final shadowColor = isDark
|
||||
? Colors.black.withOpacity(0.5)
|
||||
: Colors.black.withOpacity(0.06);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 40),
|
||||
decoration: BoxDecoration(
|
||||
color: heroBackground,
|
||||
borderRadius: BorderRadius.circular(40),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: shadowColor,
|
||||
blurRadius: 40,
|
||||
offset: const Offset(0, 24),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
days.toString(),
|
||||
style: GoogleFonts.spaceGrotesk(
|
||||
fontSize: 96,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: -3,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'days remaining',
|
||||
style: GoogleFonts.plusJakartaSans(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
letterSpacing: 0.3,
|
||||
color: colorScheme.onSurface.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_TimeUnit(value: hours, label: 'Hours'),
|
||||
const SizedBox(width: 12),
|
||||
_TimeUnit(value: minutes, label: 'Minutes'),
|
||||
const SizedBox(width: 12),
|
||||
_TimeUnit(value: seconds, label: 'Seconds'),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TimeUnit extends StatelessWidget {
|
||||
final int value;
|
||||
final String label;
|
||||
|
||||
const _TimeUnit({required this.value, required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
final backgroundColor = isDark
|
||||
? const Color(0xFF020617)
|
||||
: const Color(0xFFF3F4F6);
|
||||
final borderColor = isDark
|
||||
? Colors.white.withOpacity(0.06)
|
||||
: Colors.black.withOpacity(0.04);
|
||||
|
||||
return Semantics(
|
||||
label: '$label: $value',
|
||||
value: value.toString(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
border: Border.all(color: borderColor),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
value.toString().padLeft(2, '0'),
|
||||
style: GoogleFonts.spaceGrotesk(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.2,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label.toUpperCase(),
|
||||
style: GoogleFonts.plusJakartaSans(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
letterSpacing: 0.3,
|
||||
color: colorScheme.onSurface.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProgressRing extends StatelessWidget {
|
||||
final double progress;
|
||||
|
||||
const _ProgressRing({required this.progress});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Semantics(
|
||||
label: 'Progress ring',
|
||||
value: '${(progress * 100).toInt()} percent complete',
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
height: 200,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
value: progress,
|
||||
strokeWidth: 12,
|
||||
backgroundColor: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.3),
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
ExcludeSemantics(
|
||||
child: Text(
|
||||
'${(progress * 100).toInt()}%',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MotivationalMessage extends StatelessWidget {
|
||||
final double progress;
|
||||
|
||||
const _MotivationalMessage({required this.progress});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String message;
|
||||
if (progress < 0.1) {
|
||||
message = 'Every great journey begins with a single step. Keep going!';
|
||||
} else if (progress < 0.25) {
|
||||
message = 'You\'re building momentum. Stay focused on your goals!';
|
||||
} else if (progress < 0.5) {
|
||||
message = 'You\'re making real progress. Halfway there!';
|
||||
} else if (progress < 0.75) {
|
||||
message = 'Amazing progress! Your goals are within reach.';
|
||||
} else if (progress < 0.9) {
|
||||
message = 'Almost there! Finish strong!';
|
||||
} else {
|
||||
message = 'The final stretch. Give it your all!';
|
||||
}
|
||||
|
||||
return Card(
|
||||
color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.3),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
message,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user