104 lines
3.6 KiB
Dart
104 lines
3.6 KiB
Dart
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/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';
|
|
|
|
// TODO - Replace with actual auth state logic
|
|
final authStateProvider = FutureProvider<bool>(
|
|
(ref) async => true,
|
|
);
|
|
|
|
class StartPage extends ConsumerWidget {
|
|
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
|
|
|
|
final onboardingState = ref.watch(onboardingStateProvider);
|
|
final authState = ref.watch(authStateProvider);
|
|
final currentTrips = ref.watch(currentTripsProvider);
|
|
|
|
return onboardingState.when(
|
|
data: (isOnboarded) {
|
|
if (!isOnboarded) {
|
|
return const OnboardingPage();
|
|
}
|
|
|
|
return authState.when(
|
|
data: (isLoggedIn) {
|
|
if (!isLoggedIn) {
|
|
return const LoginPage();
|
|
}
|
|
|
|
|
|
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)),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
onPressed: () {
|
|
Navigator.of(
|
|
context,
|
|
).push(MaterialPageRoute(builder: (_) => const TripLocationSelectionPage()));
|
|
},
|
|
icon: const Icon(Icons.map),
|
|
label: const Text('Plan your next trip'),
|
|
),
|
|
);
|
|
}
|
|
}
|