511 lines
15 KiB
Dart
511 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../../core/routing/route_paths.dart';
|
|
import '../../../../core/routing/route_guards.dart';
|
|
import '../../../../shared/presentation/providers/app_providers.dart';
|
|
|
|
/// Home page with navigation to different features
|
|
class HomePage extends ConsumerWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final authState = ref.watch(authStateProvider);
|
|
final themeMode = ref.watch(themeModeProvider);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Base Flutter App'),
|
|
actions: [
|
|
// Theme toggle button
|
|
IconButton(
|
|
onPressed: () {
|
|
ref.read(themeModeProvider.notifier).toggleTheme();
|
|
},
|
|
icon: Icon(
|
|
themeMode == ThemeMode.dark
|
|
? Icons.light_mode
|
|
: themeMode == ThemeMode.light
|
|
? Icons.dark_mode
|
|
: Icons.brightness_auto,
|
|
),
|
|
tooltip: 'Toggle theme',
|
|
),
|
|
// Settings button
|
|
IconButton(
|
|
onPressed: () => context.push(RoutePaths.settings),
|
|
icon: const Icon(Icons.settings),
|
|
tooltip: 'Settings',
|
|
),
|
|
],
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Welcome section
|
|
_WelcomeCard(authState: authState),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Quick actions section
|
|
Text(
|
|
'Quick Actions',
|
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
_QuickActionsGrid(),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Features section
|
|
Text(
|
|
'Features',
|
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
_FeaturesGrid(),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Recent activity section
|
|
_RecentActivityCard(),
|
|
],
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
onPressed: () => context.push(RoutePaths.addTodo),
|
|
icon: const Icon(Icons.add),
|
|
label: const Text('Add Todo'),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _WelcomeCard extends StatelessWidget {
|
|
final AuthState authState;
|
|
|
|
const _WelcomeCard({
|
|
required this.authState,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 24,
|
|
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
|
child: Icon(
|
|
Icons.person,
|
|
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
authState == AuthState.authenticated
|
|
? 'Welcome back!'
|
|
: 'Welcome!',
|
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
authState == AuthState.authenticated
|
|
? 'Ready to be productive today?'
|
|
: 'Get started with the base Flutter app.',
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (authState == AuthState.unauthenticated) ...[
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed: () => context.push(RoutePaths.login),
|
|
child: const Text('Login'),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: FilledButton(
|
|
onPressed: () => context.push(RoutePaths.register),
|
|
child: const Text('Register'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _QuickActionsGrid extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final quickActions = [
|
|
_QuickAction(
|
|
icon: Icons.add_task,
|
|
title: 'Add Todo',
|
|
subtitle: 'Create a new task',
|
|
onTap: () => context.push(RoutePaths.addTodo),
|
|
),
|
|
_QuickAction(
|
|
icon: Icons.list,
|
|
title: 'View Todos',
|
|
subtitle: 'See all tasks',
|
|
onTap: () => context.push(RoutePaths.todos),
|
|
),
|
|
_QuickAction(
|
|
icon: Icons.settings,
|
|
title: 'Settings',
|
|
subtitle: 'App preferences',
|
|
onTap: () => context.push(RoutePaths.settings),
|
|
),
|
|
_QuickAction(
|
|
icon: Icons.info,
|
|
title: 'About',
|
|
subtitle: 'App information',
|
|
onTap: () => context.push(RoutePaths.about),
|
|
),
|
|
];
|
|
|
|
return GridView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
crossAxisSpacing: 12,
|
|
mainAxisSpacing: 12,
|
|
childAspectRatio: 1.2,
|
|
),
|
|
itemCount: quickActions.length,
|
|
itemBuilder: (context, index) {
|
|
return _QuickActionCard(action: quickActions[index]);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _FeaturesGrid extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final features = [
|
|
_Feature(
|
|
icon: Icons.check_circle_outline,
|
|
title: 'Todo Management',
|
|
description: 'Create, edit, and track your tasks efficiently.',
|
|
color: Colors.blue,
|
|
onTap: () => context.push(RoutePaths.todos),
|
|
),
|
|
_Feature(
|
|
icon: Icons.palette,
|
|
title: 'Theming',
|
|
description: 'Switch between light, dark, and system themes.',
|
|
color: Colors.purple,
|
|
onTap: () => context.push(RoutePaths.settingsTheme),
|
|
),
|
|
_Feature(
|
|
icon: Icons.storage,
|
|
title: 'Local Storage',
|
|
description: 'Hive database integration for offline support.',
|
|
color: Colors.orange,
|
|
onTap: () => context.push(RoutePaths.settings),
|
|
),
|
|
_Feature(
|
|
icon: Icons.security,
|
|
title: 'Secure Storage',
|
|
description: 'Protected storage for sensitive data.',
|
|
color: Colors.green,
|
|
onTap: () => context.push(RoutePaths.settingsPrivacy),
|
|
),
|
|
];
|
|
|
|
return GridView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
crossAxisSpacing: 12,
|
|
mainAxisSpacing: 12,
|
|
childAspectRatio: 0.8,
|
|
),
|
|
itemCount: features.length,
|
|
itemBuilder: (context, index) {
|
|
return _FeatureCard(feature: features[index]);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _RecentActivityCard extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'Recent Activity',
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () => context.push(RoutePaths.todos),
|
|
child: const Text('View All'),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
_ActivityItem(
|
|
icon: Icons.add_task,
|
|
title: 'Welcome to Base Flutter App',
|
|
subtitle: 'Your journey starts here',
|
|
time: 'Just now',
|
|
),
|
|
_ActivityItem(
|
|
icon: Icons.info,
|
|
title: 'App initialized',
|
|
subtitle: 'Database and services ready',
|
|
time: 'A few seconds ago',
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _QuickActionCard extends StatelessWidget {
|
|
final _QuickAction action;
|
|
|
|
const _QuickActionCard({
|
|
required this.action,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
child: InkWell(
|
|
onTap: action.onTap,
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
action.icon,
|
|
size: 32,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
action.title,
|
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
action.subtitle,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
|
),
|
|
textAlign: TextAlign.center,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _FeatureCard extends StatelessWidget {
|
|
final _Feature feature;
|
|
|
|
const _FeatureCard({
|
|
required this.feature,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
child: InkWell(
|
|
onTap: feature.onTap,
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: feature.color.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(
|
|
feature.icon,
|
|
color: feature.color,
|
|
size: 24,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
feature.title,
|
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Expanded(
|
|
child: Text(
|
|
feature.description,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
|
),
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ActivityItem extends StatelessWidget {
|
|
final IconData icon;
|
|
final String title;
|
|
final String subtitle;
|
|
final String time;
|
|
|
|
const _ActivityItem({
|
|
required this.icon,
|
|
required this.title,
|
|
required this.subtitle,
|
|
required this.time,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.5),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(
|
|
icon,
|
|
size: 16,
|
|
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
Text(
|
|
subtitle,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Text(
|
|
time,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _QuickAction {
|
|
final IconData icon;
|
|
final String title;
|
|
final String subtitle;
|
|
final VoidCallback onTap;
|
|
|
|
const _QuickAction({
|
|
required this.icon,
|
|
required this.title,
|
|
required this.subtitle,
|
|
required this.onTap,
|
|
});
|
|
}
|
|
|
|
class _Feature {
|
|
final IconData icon;
|
|
final String title;
|
|
final String description;
|
|
final Color color;
|
|
final VoidCallback onTap;
|
|
|
|
const _Feature({
|
|
required this.icon,
|
|
required this.title,
|
|
required this.description,
|
|
required this.color,
|
|
required this.onTap,
|
|
});
|
|
} |