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