Zenith/lib/zenith_client_provider.dart

31 lines
856 B
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
class ZenithClientProvider extends ChangeNotifier {
late Client _client;
2023-12-28 20:20:50 +00:00
bool _loading = true;
Client get client => _client;
2023-12-28 20:20:50 +00:00
bool get loading => _loading;
Future<void> initialize(
String homeserver, String username, String password) async {
2023-12-28 20:20:50 +00:00
_loading = true;
_client = Client("zenith");
2023-12-28 20:20:50 +00:00
try {
print("Checking homeserver...");
await client.checkHomeserver(Uri.parse(homeserver));
print("Logging in...");
await client.login(LoginType.mLoginPassword,
identifier: AuthenticationUserIdentifier(user: username),
password: password);
await client.roomsLoading;
await client.accountDataLoading;
2023-12-28 20:20:50 +00:00
} finally {
_loading = false;
}
notifyListeners();
}
}