Implement multi-screen app UI flow and navigation

This commit is contained in:
Rijad Zuzo
2026-02-15 13:57:24 +01:00
parent d5146d6b09
commit ac9577c759
21 changed files with 1648 additions and 60 deletions
@@ -0,0 +1,76 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:relationship_saver/features/local/local_models.dart';
import 'package:relationship_saver/features/local/local_repository.dart';
import 'package:relationship_saver/integrations/backend/backend_gateway_provider.dart';
import 'package:relationship_saver/integrations/backend/models/backend_models.dart';
class SignalsController extends AsyncNotifier<SignalsFeed> {
@override
Future<SignalsFeed> build() async {
return _load();
}
Future<void> refresh() async {
state = const AsyncLoading<SignalsFeed>();
try {
final SignalsFeed feed = await _load();
state = AsyncData<SignalsFeed>(feed);
} catch (error, stackTrace) {
state = AsyncError<SignalsFeed>(error, stackTrace);
}
}
Future<void> acknowledge(String id, SignalAction action) async {
final SignalsFeed? current = state.asData?.value;
if (current == null) {
return;
}
await ref
.read(backendGatewayProvider)
.acknowledgeSignal(signalId: id, action: action);
final List<SignalItem> updated = current.items
.where((SignalItem item) => item.id != id)
.toList(growable: false);
state = AsyncData<SignalsFeed>(current.copyWith(items: updated));
}
Future<SignalsFeed> _load() async {
try {
return await ref.read(backendGatewayProvider).getSignalsFeed(limit: 20);
} catch (_) {
final List<PersonProfile> people = ref
.read(localRepositoryProvider)
.people();
final DateTime now = DateTime.now().toUtc();
return SignalsFeed(
cursor: 'fallback-signals',
items: <SignalItem>[
SignalItem(
id: 'fallback-1',
type: 'recommendation',
title: 'Check in with ${people.first.name} tonight',
description: 'A short voice memo can keep momentum.',
personId: people.first.id,
createdAt: now,
),
SignalItem(
id: 'fallback-2',
type: 'trend',
title: 'Gift idea: practical + personal is trending',
description: 'Combine utility with one sentimental detail.',
personId: people.last.id,
createdAt: now.subtract(const Duration(hours: 2)),
),
],
);
}
}
}
final AsyncNotifierProvider<SignalsController, SignalsFeed>
signalsControllerProvider =
AsyncNotifierProvider<SignalsController, SignalsFeed>(
SignalsController.new,
);
+158
View File
@@ -0,0 +1,158 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:relationship_saver/core/config/app_theme.dart';
import 'package:relationship_saver/features/shared/frosted_card.dart';
import 'package:relationship_saver/features/signals/signals_controller.dart';
import 'package:relationship_saver/integrations/backend/models/backend_models.dart';
class SignalsView extends ConsumerWidget {
const SignalsView({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final AsyncValue<SignalsFeed> signals = ref.watch(
signalsControllerProvider,
);
return Padding(
padding: const EdgeInsets.fromLTRB(28, 24, 28, 28),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Signals',
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 6),
Text(
'Backend-driven recommendations and trends you can act on.',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: AppTheme.textSecondary,
),
),
],
),
),
IconButton.filledTonal(
onPressed: () {
ref.read(signalsControllerProvider.notifier).refresh();
},
icon: const Icon(Icons.refresh_rounded),
tooltip: 'Refresh feed',
),
],
),
const SizedBox(height: 16),
Expanded(
child: signals.when(
data: (SignalsFeed feed) {
if (feed.items.isEmpty) {
return const Center(child: Text('No signals right now.'));
}
return ListView.separated(
itemCount: feed.items.length,
separatorBuilder: (_, _) => const SizedBox(height: 12),
itemBuilder: (BuildContext context, int index) {
final SignalItem item = feed.items[index];
return FrostedCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 6,
),
decoration: BoxDecoration(
color: const Color(0xFFEAF8FB),
borderRadius: BorderRadius.circular(99),
),
child: Text(
item.type.toUpperCase(),
style: Theme.of(context).textTheme.labelMedium
?.copyWith(
color: AppTheme.primary,
fontWeight: FontWeight.w700,
),
),
),
const Spacer(),
Text(
'${item.createdAt.month}/${item.createdAt.day}',
style: Theme.of(context).textTheme.bodySmall
?.copyWith(color: AppTheme.textSecondary),
),
],
),
const SizedBox(height: 12),
Text(
item.title,
style: Theme.of(context).textTheme.titleLarge,
),
if (item.description case final String description)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
description,
style: Theme.of(context).textTheme.bodyLarge
?.copyWith(color: AppTheme.textSecondary),
),
),
const SizedBox(height: 14),
Row(
children: <Widget>[
OutlinedButton.icon(
onPressed: () {
ref
.read(signalsControllerProvider.notifier)
.acknowledge(item.id, SignalAction.saved);
},
icon: const Icon(Icons.bookmark_add_outlined),
label: const Text('Save'),
),
const SizedBox(width: 8),
TextButton.icon(
onPressed: () {
ref
.read(signalsControllerProvider.notifier)
.acknowledge(
item.id,
SignalAction.dismissed,
);
},
icon: const Icon(Icons.close_rounded),
label: const Text('Dismiss'),
),
],
),
],
),
);
},
);
},
error: (Object error, StackTrace stackTrace) {
return Center(
child: Text(
'Unable to load signals. Try refresh.',
style: Theme.of(context).textTheme.bodyLarge,
),
);
},
loading: () => const Center(child: CircularProgressIndicator()),
),
),
],
),
);
}
}