Zenith/lib/zenith_client_provider.dart

31 lines
856 B
Dart

import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
class ZenithClientProvider extends ChangeNotifier {
late Client _client;
bool _loading = true;
Client get client => _client;
bool get loading => _loading;
Future<void> initialize(
String homeserver, String username, String password) async {
_loading = true;
_client = Client("zenith");
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;
} finally {
_loading = false;
}
notifyListeners();
}
}