quite a few UX improvements
This commit is contained in:
		
							
								
								
									
										17
									
								
								frontend/lib/structs/agreement.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								frontend/lib/structs/agreement.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| import 'package:shared_preferences/shared_preferences.dart'; | ||||
|  | ||||
| final class Agreement{ | ||||
|   bool agreed; | ||||
|  | ||||
|   Agreement({required this.agreed}); | ||||
| } | ||||
|  | ||||
| void saveAgreement(bool agreed) async { | ||||
|   SharedPreferences prefs = await SharedPreferences.getInstance(); | ||||
|   prefs.setBool('agreed_to_terms_and_conditions', agreed); | ||||
| } | ||||
|  | ||||
| Future<Agreement> getAgreement() async { | ||||
|   SharedPreferences prefs = await SharedPreferences.getInstance(); | ||||
|   return Agreement(agreed: prefs.getBool('agreed_to_terms_and_conditions') ?? false); | ||||
| } | ||||
| @@ -12,7 +12,7 @@ import 'package:shared_preferences/shared_preferences.dart'; | ||||
|  | ||||
| class Trip with ChangeNotifier { | ||||
|   String uuid; | ||||
|   int totalTime; | ||||
|   Duration totalTime; | ||||
|   LinkedList<Landmark> landmarks; | ||||
|   // could be empty as well | ||||
|   String? errorDescription; | ||||
| @@ -44,7 +44,7 @@ class Trip with ChangeNotifier { | ||||
|  | ||||
|   Trip({ | ||||
|     this.uuid = 'pending', | ||||
|     this.totalTime = 0, | ||||
|     this.totalTime = Duration.zero, | ||||
|     LinkedList<Landmark>? landmarks | ||||
|     // a trip can be created with no landmarks, but the list should be initialized anyway | ||||
|   }) : landmarks = landmarks ?? LinkedList<Landmark>(); | ||||
| @@ -53,7 +53,7 @@ class Trip with ChangeNotifier { | ||||
|   factory Trip.fromJson(Map<String, dynamic> json) { | ||||
|     Trip trip = Trip( | ||||
|       uuid: json['uuid'], | ||||
|       totalTime: json['total_time'], | ||||
|       totalTime: Duration(minutes: json['total_time']), | ||||
|     ); | ||||
|  | ||||
|     return trip; | ||||
| @@ -61,7 +61,7 @@ class Trip with ChangeNotifier { | ||||
|  | ||||
|   void loadFromJson(Map<String, dynamic> json) { | ||||
|     uuid = json['uuid']; | ||||
|     totalTime = json['total_time']; | ||||
|     totalTime = Duration(minutes: json['total_time']); | ||||
|     notifyListeners(); | ||||
|   } | ||||
|  | ||||
| @@ -82,9 +82,12 @@ class Trip with ChangeNotifier { | ||||
|     // removing the landmark means we need to recompute the time between the two adjoined landmarks | ||||
|     if (previous != null && next != null) { | ||||
|       // previous.next = next happens automatically since we are using a LinkedList | ||||
|       this.totalTime -= previous.tripTime ?? Duration.zero; | ||||
|       previous.tripTime = null; | ||||
|       // TODO | ||||
|     } | ||||
|     this.totalTime -= landmark.tripTime ?? Duration.zero; | ||||
|  | ||||
|     notifyListeners(); | ||||
|   } | ||||
|  | ||||
| @@ -111,7 +114,7 @@ class Trip with ChangeNotifier { | ||||
|  | ||||
|   Map<String, dynamic> toJson() => { | ||||
|     'uuid': uuid, | ||||
|     'total_time': totalTime, | ||||
|     'total_time': totalTime.inMinutes, | ||||
|     'first_landmark_uuid': landmarks.first.uuid | ||||
|   }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user