
Hey there! im following this tutorial https://devdactic.com/flutter-authentication-appwrite on creating a login and register screen.
ive tried to do the exact same, but for some reason my app either crashes when logging in or gives me the following errors:
flutter: Error: LateInitializationError: Field 'account' has not been initialized.
flutter: Error: Creation of a session is prohibited when a session is active.
flutter: Initialization complete
flutter: value: AuthStatus.unauthenticated
I will provide you with the code shortly.

import 'dart:async';
import 'package:appwrite/models.dart';
import 'package:flutter/foundation.dart';
import 'package:appwrite/appwrite.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:servicescheinapp/constants/constants.dart';
enum AuthStatus {
uninitialized,
authenticated,
unauthenticated,
}
// Helper class for the appwrite database
// connects to Database and Storage
class AppWriteAuth extends ChangeNotifier {
Client client = Client();
late final Account account;
late User _currentUser;
AuthStatus _status = AuthStatus.uninitialized;
// Getter methods
User get currentUser => _currentUser;
AuthStatus get status => _status;
String? get username => _currentUser?.name;
String? get email => _currentUser?.email;
String? get userid => _currentUser?.$id;
AppWriteAuth() {
init();
loadUser();
}
init() async {
await dotenv.load(fileName: "constants.env");
String serverURL = dotenv.env['SERVER_URL']!;
String apiEndpoint = 'v1';
client
.setEndpoint('$serverURL$apiEndpoint')
.setProject(appwriteProjectID2)
.setSelfSigned(status: true);
// For self signed certificates, only use for development
account = Account(client);
print('Initialization complete');
}
loadUser() async {
try {
final user = await account.get();
_status = AuthStatus.authenticated;
_currentUser = user;
} catch (e) {
_status = AuthStatus.unauthenticated;
} finally {
notifyListeners();
}
}
Future<User> createUser(
{required String email, required String password}) async {
try {
final user = await account.create(
userId: ID.unique(), email: email, password: password);
return user;
} finally {
notifyListeners();
}
}
Future<Session> createEmailSession(
{required String email, required String password}) async {
try {
final session = await account.createEmailPasswordSession(
email: email, password: password);
_currentUser = await account.get();
_status = AuthStatus.authenticated;
return session;
} finally {
notifyListeners();
}
}
// check Authentication state
Future<void> checkAuth() async {
try {
_currentUser = await account.get();
// Logged in
print('Logged in and authenticated');
print('User: ${_currentUser.email}');
} catch (e) {
// Not logged in
print('Not logged in');
print('Error: $e');
}
}
signOut() async {
try {
await account.deleteSession(sessionId: 'current');
_status = AuthStatus.unauthenticated;
} finally {
notifyListeners();
}
}
}
This is my auth file

This is my LOGIN page.
i use the register and password forgot button to test signout/ if user is logged in.

current behaviour is:
either crashes with correct login info or gives me these errors:
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: type 'Null' is not a subtype of type 'bool'
#0 new Target.fromMap (package:appwrite/src/models/target.dart:54:19)
#1 new User.fromMap.<anonymous closure> (package:appwrite/src/models/user.dart:103:67)
#2 MappedListIterable.elementAt (dart:_internal/iterable.dart:442:31)
#3 ListIterator.moveNext (dart:_internal/iterable.dart:371:26)
#4 new List.from (dart:core-patch/array_patch.dart:30:17)
#5 new User.fromMap (package:appwrite/src/models/user.dart:103:16)
#6 Account.get (package:appwrite/services/account.dart:23:24)
<asynchronous suspension>
#7 AppWriteAuth.createEmailSession (package:servicescheinapp/backend/appwrite/appwrite_auth.dart:76:22)
<asynchronous suspension>
#8 _AppwriteLoginState.signIn (package:servicescheinapp/backend/appwrite/appwrite_login.dart:37:7)
<asynchronous suspension>
flutter: value: AuthStatus.unauthenticated
checking account with getAUTH
gives me flutter: Error: LateInitializationError: Field 'account' has not been initialized.
I also use the Provider package as in the tutorial

Appwrite Login Issue login does not work
Recommended threads
- 404 errors after 7 Days
Local hosted Appwrite via docker. Last version and current version. After exactly 7 days Appwrite stops working. I get 404 route not found, cannot access anyth...
- unable to modify attribute
please help: when I try to modify attribute size or key or anything, I am getting this errors: ``` Deprecated: strtolower(): Passing null to parameter #1 ($str...
- Error 1.7.4 console team no found
In console when i go to auth, select user, select a membership the url not work. Only work searching the team. It is by the region. project-default- and i get ...
