quite a few UX improvements

This commit is contained in:
2025-03-23 20:00:24 +01:00
parent 4ad867e609
commit e148c851e1
12 changed files with 166 additions and 60 deletions

View File

@@ -1,44 +1,50 @@
import 'package:anyway/main.dart';
import 'package:anyway/pages/no_trips_page.dart';
import 'package:anyway/structs/agreement.dart';
import 'package:flutter/material.dart';
import 'package:anyway/structs/trip.dart';
import 'package:anyway/utils/load_trips.dart';
import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/pages/onboarding.dart';
Widget getFirstPage() {
SavedTrips trips = savedTrips;
trips.loadTrips();
return ListenableBuilder(
listenable: trips,
builder: (BuildContext context, Widget? child) {
List<Trip> items = trips.trips;
if (items.isNotEmpty) {
return TripPage(trip: items[0]);
// check if the user has already seen the onboarding and agreed to the terms of service
return FutureBuilder(
future: getAgreement(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
Agreement agrement = snapshot.data!;
if (agrement.agreed) {
return FutureBuilder(
future: savedTrips.loadTrips(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
List<Trip> trips = snapshot.data!;
if (trips.length > 0) {
return TripPage(trip: trips[0]);
} else {
return NoTripsPage();
}
} else {
return Center(child: CircularProgressIndicator());
}
} else {
return Center(child: CircularProgressIndicator());
}
},
);
} else {
return OnboardingPage();
}
} else {
return OnboardingPage();
}
} else {
return const OnboardingPage();
return OnboardingPage();
}
}
},
);
// Future<List<Trip>> trips = loadTrips();
// // test if there are any active trips
// // if there are, return the trip list
// // if there are not, return the onboarding page
// return FutureBuilder(
// future: trips,
// builder: (context, snapshot) {
// if (snapshot.hasData) {
// List<Trip> availableTrips = snapshot.data!;
// if (availableTrips.isNotEmpty) {
// return TripPage(trip: availableTrips[0]);
// } else {
// return OnboardingPage();
// }
// } else {
// return CircularProgressIndicator();
// }
// }
// );
}

View File

@@ -8,7 +8,7 @@ class SavedTrips extends ChangeNotifier {
List<Trip> get trips => _trips;
void loadTrips() async {
Future<List<Trip>> loadTrips() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<Trip> trips = [];
@@ -21,6 +21,7 @@ class SavedTrips extends ChangeNotifier {
}
_trips = trips;
notifyListeners();
return trips;
}
void addTrip(Trip trip) async {