revamp new trip flow
This commit is contained in:
		| @@ -1,5 +1,4 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:shared_preferences/shared_preferences.dart'; | ||||
|  | ||||
|  | ||||
| class SinglePreference { | ||||
| @@ -20,16 +19,6 @@ class SinglePreference { | ||||
|     this.minVal = 0, | ||||
|     this.maxVal = 5, | ||||
|   }); | ||||
|  | ||||
|   void save() async { | ||||
|     SharedPreferences sharedPrefs = await SharedPreferences.getInstance(); | ||||
|       sharedPrefs.setInt('pref_$slug', value); | ||||
|   } | ||||
|  | ||||
|   void load() async { | ||||
|     SharedPreferences sharedPrefs = await SharedPreferences.getInstance(); | ||||
|       value = sharedPrefs.getInt('pref_$slug') ?? minVal; | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -65,38 +54,15 @@ class UserPreferences { | ||||
|     maxVal: 720, | ||||
|     icon: Icon(Icons.timer), | ||||
|   ); | ||||
|   SinglePreference maxDetour = SinglePreference( | ||||
|     name: "Trip detours", | ||||
|     slug: "detours", | ||||
|     description: "Are you okay with roaming even if makes the trip longer?", | ||||
|     value: 0, | ||||
|     maxVal: 30, | ||||
|     icon: Icon(Icons.loupe_sharp), | ||||
|   ); | ||||
|  | ||||
|  | ||||
|  | ||||
|   Future<void> load() async { | ||||
|     for (SinglePreference pref in [sightseeing, shopping, nature, maxTime, maxDetour]) { | ||||
|       pref.load(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   Map<String, dynamic> toJson() { | ||||
|       // This is "opinionated" JSON, corresponding to the backend's expectations | ||||
|       return { | ||||
|         "sightseeing": {"type": "sightseeing", "score": sightseeing.value}, | ||||
|         "shopping": {"type": "shopping", "score": shopping.value}, | ||||
|         "nature": {"type": "nature", "score": nature.value}, | ||||
|         "max_time_minute": maxTime.value, | ||||
|         "detour_tolerance_minute": maxDetour.value | ||||
|         "max_time_minute": maxTime.value | ||||
|       }; | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| Future<UserPreferences> loadUserPreferences() async { | ||||
|   UserPreferences prefs = UserPreferences(); | ||||
|   await prefs.load(); | ||||
|   return prefs; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user