List rooms in chats.dart
This commit is contained in:
parent
112fe960be
commit
a6306ceddc
|
@ -1,7 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:zenith/zenith_client_provider.dart';
|
||||
|
||||
class ChatsPage extends StatefulWidget {
|
||||
|
@ -15,16 +13,10 @@ class _ChatsPageState extends State<ChatsPage> {
|
|||
final serverController = TextEditingController();
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
late Client client;
|
||||
bool roomsLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
client = Provider.of<ZenithClientProvider>(context, listen: false).client;
|
||||
client.onRoomState.stream.listen((event) {
|
||||
print(event.type);
|
||||
});
|
||||
}
|
||||
|
||||
void sendMessage() {}
|
||||
|
@ -38,14 +30,18 @@ class _ChatsPageState extends State<ChatsPage> {
|
|||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Center(
|
||||
child: roomsLoading
|
||||
? const CircularProgressIndicator()
|
||||
: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [Text("${client.rooms.length} Rooms.")],
|
||||
),
|
||||
),
|
||||
child: Center(child: Consumer<ZenithClientProvider>(
|
||||
builder: (context, provider, child) {
|
||||
if (provider.loading)
|
||||
return const CircularProgressIndicator();
|
||||
else
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(provider.client.rooms[index]
|
||||
.getLocalizedDisplayname()),
|
||||
));
|
||||
},
|
||||
)),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: sendMessage,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:zenith/chats.dart';
|
||||
|
|
|
@ -3,23 +3,26 @@ import 'package:matrix/matrix.dart';
|
|||
|
||||
class ZenithClientProvider extends ChangeNotifier {
|
||||
late Client _client;
|
||||
bool _loading = true;
|
||||
|
||||
Client get client => _client;
|
||||
|
||||
void setClient(Client newClient) {
|
||||
_client = newClient;
|
||||
notifyListeners();
|
||||
}
|
||||
bool get loading => _loading;
|
||||
|
||||
Future<void> initialize(
|
||||
String homeserver, String username, String password) async {
|
||||
_loading = true;
|
||||
_client = Client("zenith");
|
||||
print("Checking homeserver...");
|
||||
await client.checkHomeserver(Uri.parse(homeserver));
|
||||
print("Logging in...");
|
||||
await client.login(LoginType.mLoginPassword,
|
||||
identifier: AuthenticationUserIdentifier(user: username),
|
||||
password: password);
|
||||
try {
|
||||
print("Checking homeserver...");
|
||||
await client.checkHomeserver(Uri.parse(homeserver));
|
||||
print("Logging in...");
|
||||
await client.login(LoginType.mLoginPassword,
|
||||
identifier: AuthenticationUserIdentifier(user: username),
|
||||
password: password);
|
||||
} finally {
|
||||
_loading = false;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user