f655adfbea
Migrate app code into canonical feature slices, add phone-only AI digest scheduling and review, wire local notification/background task support, and cover the flow with tests.
382 lines
13 KiB
Dart
382 lines
13 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:relationship_saver/app/navigation/app_destination.dart';
|
|
import 'package:relationship_saver/core/config/app_theme.dart';
|
|
import 'package:relationship_saver/features/ai_digest/presentation/ai_digest_review_view.dart';
|
|
import 'package:relationship_saver/features/dashboard/presentation/dashboard_view.dart';
|
|
import 'package:relationship_saver/features/ideas/presentation/ideas_view.dart';
|
|
import 'package:relationship_saver/features/moments/presentation/moments_view.dart';
|
|
import 'package:relationship_saver/features/people/presentation/people_view.dart';
|
|
import 'package:relationship_saver/features/reminders/presentation/reminders_view.dart';
|
|
import 'package:relationship_saver/features/settings/presentation/settings_view.dart';
|
|
import 'package:relationship_saver/features/signals/presentation/signals_view.dart';
|
|
import 'package:relationship_saver/features/sync/presentation/sync_view.dart';
|
|
|
|
/// Responsive shell that hosts the main feature slices.
|
|
class AppShell extends ConsumerStatefulWidget {
|
|
const AppShell({super.key});
|
|
|
|
@override
|
|
ConsumerState<AppShell> createState() => _AppShellState();
|
|
}
|
|
|
|
class _AppShellState extends ConsumerState<AppShell> {
|
|
AppDestination _destination = AppDestination.dashboard;
|
|
|
|
static const List<AppDestination> _destinations = AppDestination.values;
|
|
static const List<AppDestination> _compactPrimaryDestinations =
|
|
<AppDestination>[
|
|
AppDestination.dashboard,
|
|
AppDestination.people,
|
|
AppDestination.moments,
|
|
AppDestination.signals,
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DecoratedBox(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: <Color>[
|
|
Color(0xFFF3F8FB),
|
|
Color(0xFFEAF1F8),
|
|
Color(0xFFF8FAFC),
|
|
],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
),
|
|
child: Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
body: SafeArea(
|
|
child: LayoutBuilder(
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
|
if (constraints.maxWidth < 1000) {
|
|
return _buildCompactLayout(context);
|
|
}
|
|
|
|
return Row(
|
|
children: <Widget>[
|
|
_Sidebar(
|
|
selected: _destination,
|
|
destinations: _destinations,
|
|
onChange: _selectDestination,
|
|
),
|
|
Expanded(
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 250),
|
|
child: KeyedSubtree(
|
|
key: ValueKey<AppDestination>(_destination),
|
|
child: _screenFor(_destination),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCompactLayout(BuildContext context) {
|
|
final int compactIndex = _compactSelectedIndex(_destination);
|
|
final AppDestination active = _compactPrimaryDestinations[compactIndex];
|
|
return _CompactShell(
|
|
title: active.label,
|
|
selected: active,
|
|
body: _screenFor(active),
|
|
destinations: _compactPrimaryDestinations,
|
|
onChange: _selectDestination,
|
|
onOpenSecondary: (CompactSecondaryDestination destination) {
|
|
final AppDestination screenDestination = switch (destination) {
|
|
CompactSecondaryDestination.ideas => AppDestination.ideas,
|
|
CompactSecondaryDestination.aiReview => AppDestination.aiReview,
|
|
CompactSecondaryDestination.reminders => AppDestination.reminders,
|
|
CompactSecondaryDestination.sync => AppDestination.sync,
|
|
CompactSecondaryDestination.settings => AppDestination.settings,
|
|
};
|
|
|
|
Navigator.of(context).push<void>(
|
|
MaterialPageRoute<void>(
|
|
builder: (BuildContext context) {
|
|
return _CompactSecondaryScreen(
|
|
title: screenDestination.label,
|
|
child: _screenFor(screenDestination),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _selectDestination(AppDestination destination) {
|
|
setState(() {
|
|
_destination = destination;
|
|
});
|
|
}
|
|
|
|
int _compactSelectedIndex(AppDestination destination) {
|
|
for (int i = 0; i < _compactPrimaryDestinations.length; i += 1) {
|
|
if (_compactPrimaryDestinations[i] == destination) {
|
|
return i;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
Widget _screenFor(AppDestination destination) {
|
|
switch (destination) {
|
|
case AppDestination.dashboard:
|
|
return const DashboardView();
|
|
case AppDestination.people:
|
|
return const PeopleView();
|
|
case AppDestination.moments:
|
|
return const MomentsView();
|
|
case AppDestination.signals:
|
|
return const SignalsView();
|
|
case AppDestination.aiReview:
|
|
return const AiDigestReviewView();
|
|
case AppDestination.ideas:
|
|
return const IdeasView();
|
|
case AppDestination.reminders:
|
|
return const RemindersView();
|
|
case AppDestination.sync:
|
|
return const SyncView();
|
|
case AppDestination.settings:
|
|
return const SettingsView();
|
|
}
|
|
}
|
|
}
|
|
|
|
class _Sidebar extends StatelessWidget {
|
|
const _Sidebar({
|
|
required this.selected,
|
|
required this.destinations,
|
|
required this.onChange,
|
|
});
|
|
|
|
final AppDestination selected;
|
|
final List<AppDestination> destinations;
|
|
final ValueChanged<AppDestination> onChange;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: 290,
|
|
margin: const EdgeInsets.fromLTRB(20, 20, 8, 20),
|
|
padding: const EdgeInsets.fromLTRB(18, 20, 18, 18),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.78),
|
|
borderRadius: BorderRadius.circular(28),
|
|
border: Border.all(color: Colors.white.withValues(alpha: 0.7)),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Row(
|
|
children: <Widget>[
|
|
Container(
|
|
width: 34,
|
|
height: 34,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
gradient: const LinearGradient(
|
|
colors: <Color>[Color(0xFF1AB6C8), Color(0xFF286DE0)],
|
|
),
|
|
),
|
|
child: const Icon(
|
|
Icons.favorite_rounded,
|
|
color: Colors.white,
|
|
size: 20,
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Text(
|
|
'Relationship Saver',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 22),
|
|
...destinations.map((AppDestination destination) {
|
|
final bool isSelected = destination == selected;
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 6),
|
|
child: InkWell(
|
|
onTap: () => onChange(destination),
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 12,
|
|
vertical: 10,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: isSelected
|
|
? const Color(0xFFEAF7FB)
|
|
: Colors.transparent,
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Icon(
|
|
destination.icon,
|
|
size: 20,
|
|
color: isSelected
|
|
? AppTheme.primary
|
|
: AppTheme.textSecondary,
|
|
),
|
|
const SizedBox(width: 10),
|
|
Text(
|
|
destination.label,
|
|
style: Theme.of(context).textTheme.titleMedium
|
|
?.copyWith(
|
|
color: isSelected
|
|
? AppTheme.primary
|
|
: AppTheme.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
const Spacer(),
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF2F8FB),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Text(
|
|
'Tip: Use Signals daily and convert at least one into a concrete plan.',
|
|
style: Theme.of(
|
|
context,
|
|
).textTheme.bodyMedium?.copyWith(color: AppTheme.textSecondary),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _CompactShell extends StatelessWidget {
|
|
const _CompactShell({
|
|
required this.title,
|
|
required this.selected,
|
|
required this.body,
|
|
required this.destinations,
|
|
required this.onChange,
|
|
required this.onOpenSecondary,
|
|
});
|
|
|
|
final String title;
|
|
final AppDestination selected;
|
|
final Widget body;
|
|
final List<AppDestination> destinations;
|
|
final ValueChanged<AppDestination> onChange;
|
|
final ValueChanged<CompactSecondaryDestination> onOpenSecondary;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: Text(
|
|
title,
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
),
|
|
PopupMenuButton<CompactSecondaryDestination>(
|
|
tooltip: 'More',
|
|
icon: const Icon(Icons.more_horiz_rounded),
|
|
onSelected: onOpenSecondary,
|
|
itemBuilder: (BuildContext context) =>
|
|
<PopupMenuEntry<CompactSecondaryDestination>>[
|
|
const PopupMenuItem<CompactSecondaryDestination>(
|
|
value: CompactSecondaryDestination.aiReview,
|
|
child: Text('AI Review'),
|
|
),
|
|
const PopupMenuItem<CompactSecondaryDestination>(
|
|
value: CompactSecondaryDestination.ideas,
|
|
child: Text('Ideas'),
|
|
),
|
|
const PopupMenuItem<CompactSecondaryDestination>(
|
|
value: CompactSecondaryDestination.reminders,
|
|
child: Text('Reminders'),
|
|
),
|
|
const PopupMenuItem<CompactSecondaryDestination>(
|
|
value: CompactSecondaryDestination.sync,
|
|
child: Text('Sync'),
|
|
),
|
|
const PopupMenuItem<CompactSecondaryDestination>(
|
|
value: CompactSecondaryDestination.settings,
|
|
child: Text('Settings'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 220),
|
|
child: KeyedSubtree(
|
|
key: ValueKey<AppDestination>(selected),
|
|
child: body,
|
|
),
|
|
),
|
|
),
|
|
NavigationBar(
|
|
selectedIndex: destinations.indexOf(selected),
|
|
onDestinationSelected: (int index) => onChange(destinations[index]),
|
|
destinations: destinations
|
|
.map(
|
|
(AppDestination destination) => NavigationDestination(
|
|
icon: Icon(destination.icon),
|
|
label: destination.label,
|
|
),
|
|
)
|
|
.toList(growable: false),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _CompactSecondaryScreen extends StatelessWidget {
|
|
const _CompactSecondaryScreen({required this.title, required this.child});
|
|
|
|
final String title;
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DecoratedBox(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: <Color>[Color(0xFFF3F8FB), Color(0xFFEAF1F8)],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
),
|
|
child: Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: AppBar(title: Text(title)),
|
|
body: child,
|
|
),
|
|
);
|
|
}
|
|
}
|