I am trying to resolve this issue, the first time I login in my app, everything is ok, but when I logout and login again, the current user (retrieved from parse) is the previous one. If I call again for the current user in another widget, the current user is the correct one, but not in the beginning.
I think that the logout method is the correct one because, as I explained before, in other widgets later in the app, the current user is the right one.
static Future<void> logOut() async {
ParseUser currentUser = await ParseUser.currentUser();
ParseResponse userResponse =
await ParseUser.getCurrentUserFromServer(currentUser.sessionToken);
ParseUser user = userResponse.result as ParseUser;
await user.logout(deleteLocalUserData: true);
}
This is the login method
Future<ParseResponse> login() async {
try {
final Map<String, dynamic> queryParams = <String, String>{
keyVarUsername: username,
keyVarPassword: password
};
final Uri url = getSanitisedUri(_client, '$keyEndPointLogin',
queryParams: queryParams);
_saveChanges();
final Response response =
await _client.get(url, headers: <String, String>{
keyHeaderRevocableSession: '1',
});
return await _handleResponse(
this, response, ParseApiRQ.login, _debug, parseClassName);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.login, _debug, parseClassName);
}
}
This is the class that appears just after the login is completed and where i try to retrieve the current user, achieving the previous user.
class UserInterfaceAppPage extends StatefulWidget {
@override
_UserInterfaceAppPageState createState() => _UserInterfaceAppPageState();
}
class _UserInterfaceAppPageState extends State<UserInterfaceAppPage> {
int _currentIndex = 0;
static List<Widget> _widgetOptions = <Widget>[];
Future<SharedPreferences> pref;
Future<bool> dishes;
_UserInterfaceAppPageState() {
initState();
}
@override
void initState() {
super.initState();
dishes = DbHelper.insertDishes();
Future<User> _currentUser = ParseManager().getActualUser();
This is the getActualUser() method where I retrieve the current user.
Future<User> getActualUser() async {
ParseUser currentUser = await ParseUser.currentUser();
ParseResponse userResponse =
await ParseUser.getCurrentUserFromServer(currentUser.sessionToken);
ParseUser user = userResponse.result as ParseUser;
User actualUser = User.fromParse(user);
return actualUser;
}
Please, let me know if you need more information of any method or class in my app. I tried so many things, included updating the SDK but i have the latest version and I could not find a similar issue.
Finally this is the output of flutter doctor
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale es-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
[✓] Android Studio (version 3.6)
[!] VS Code (version 1.43.0)
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (1 available)
! Doctor found issues in 1 category.