First, i am using MVVM
i made a DioFactory class for get dio object
This class for dependency injection and i call the initialAppModuleClass() before the runApp method
This For App Preferences for data in shared Preference
When login is success i store the token in shared Preference
When go to home screen and i called any api with token it not work, it did not get the token it still empty although it store in shared preference and take the first object of _headers in dio.
Because you are intializing the token when create the Dio Factory Even if the token in sharedPrefs is changed but still the value in Dio factory as the first time you added. The soluation is pass the token for the api header if you are using retrofit package you can do this @Header("user-token") String token
then in api call you can use the sharedprefs to pass token to the header
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.