feat(wip): implement trip persistence through a local repository. Include loaded trips in the start page UI

This commit is contained in:
2025-12-30 00:51:40 +01:00
parent 81ed2fd8c3
commit 014b48591e
28 changed files with 2395 additions and 387 deletions

View File

@@ -1,107 +1,103 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:anyway/presentation/providers/onboarding_state_provider.dart';
import 'package:anyway/domain/entities/trip.dart';
import 'package:anyway/presentation/pages/login.dart';
import 'package:anyway/presentation/pages/onboarding.dart';
import 'package:anyway/presentation/pages/new_trip_preferences.dart';
import 'package:anyway/presentation/pages/trip_creation_flow.dart';
import 'package:anyway/presentation/pages/trip_details_page.dart';
import 'package:anyway/presentation/providers/trip_provider.dart';
import 'package:anyway/presentation/widgets/trip_summary_card.dart';
// Example providers (replace these with your actual providers)
// final onboardingStateProvider = Provider<bool>((ref) => true); // Replace with actual onboarding state logic
final authStateProvider = FutureProvider<bool>((ref) async => true); // Replace with actual auth state logic
final tripsAvailableProvider = FutureProvider<bool>((ref) async => false); // Replace with actual trips availability logic
// TODO - Replace with actual auth state logic
final authStateProvider = FutureProvider<bool>(
(ref) async => true,
);
class StartPage extends ConsumerWidget {
const StartPage({Key? key}) : super(key: key);
const StartPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
// the home page is dependent on the state of the providers:
// - if the user is not onboarded, show the onboarding flow
// - if the user is not logged in, show the login page
// - if there are no trips available, show the trip creation page
// - else: show the overview page that shows the last trip
// the home page is dependent on the state of the providers:
// - if the user is not onboarded, show the onboarding flow
// - if the user is not logged in, show the login page
// - if there are no trips available, show the trip creation page
// - else: show the overview page that shows the last trip
final onboardingState = ref.watch(onboardingStateProvider);
final authState = ref.watch(authStateProvider);
final currentTrips = ref.watch(currentTripsProvider);
final onboardingState = ref.watch(onboardingStateProvider);
final authState = ref.watch(authStateProvider);
final tripsAvailable = ref.watch(tripsAvailableProvider);
return onboardingState.when(
data: (isOnboarded) {
if (!isOnboarded) {
return const OnboardingPage();
}
return onboardingState.when(
data: (isOnboarded) {
if (!isOnboarded) {
return const OnboardingPage();
}
return authState.when(
data: (isLoggedIn) {
if (!isLoggedIn) {
return const LoginPage();
}
return authState.when(
data: (isLoggedIn) {
if (!isLoggedIn) {
return const LoginPage();
}
return tripsAvailable.when(
data: (hasTrips) {
if (!hasTrips) {
return const TripCreationPage();
}
return const OverviewPage();
},
loading: () => const Scaffold(
body: Center(child: CircularProgressIndicator()),
),
error: (error, stack) => Scaffold(
body: Center(child: Text('Error: $error')),
),
return currentTrips.when(
data: (trips) {
if (trips.isEmpty) {
return const TripLocationSelectionPage();
}
return TripsOverviewPage(trips: trips);
},
loading: () => const Scaffold(body: Center(child: CircularProgressIndicator())),
error: (error, stack) => Scaffold(body: Center(child: Text('Error loading trips: $error'))),
);
},
loading: () => const Scaffold(body: Center(child: CircularProgressIndicator())),
error: (error, stack) => Scaffold(body: Center(child: Text('Error: $error'))),
);
},
loading: () => const Scaffold(body: Center(child: CircularProgressIndicator())),
error: (error, stack) => Scaffold(body: Center(child: Text('Error: $error'))),
);
}
}
// TODO - move to separate file
class TripsOverviewPage extends StatelessWidget {
const TripsOverviewPage({super.key, required this.trips});
final List<Trip> trips;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Your trips')),
body: ListView.separated(
padding: const EdgeInsets.all(16),
itemCount: trips.length,
separatorBuilder: (context, index) => const SizedBox(height: 16),
itemBuilder: (context, index) {
final trip = trips[index];
return TripSummaryCard(
trip: trip,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => TripDetailsPage(trip: trip)),
);
},
loading: () => const Scaffold(
body: Center(child: CircularProgressIndicator()),
),
error: (error, stack) => Scaffold(
body: Center(child: Text('Error: $error')),
),
);
},
loading: () => const Scaffold(
body: Center(child: CircularProgressIndicator()),
),
error: (error, stack) => Scaffold(
body: Center(child: Text('Error: $error')
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Navigator.of(
context,
).push(MaterialPageRoute(builder: (_) => const TripLocationSelectionPage()));
},
icon: const Icon(Icons.map),
label: const Text('Plan your next trip'),
),
);
}
}
class TripCreationPage extends StatelessWidget {
const TripCreationPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Create a Trip')),
body: Center(
child: ElevatedButton.icon(
icon: const Icon(Icons.tune),
label: const Text('Set Preferences'),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const NewTripPreferencesPage()));
},
),
),
);
}
}
class OverviewPage extends StatelessWidget {
const OverviewPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Text('Overview Page')),
);
}
}