View messages for a room
This commit is contained in:
parent
a6306ceddc
commit
3352939009
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:zenith/chats.dart';
|
||||
import 'package:zenith/rooms.dart';
|
||||
import 'package:zenith/zenith_client_provider.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
|
@ -29,7 +29,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
if (!mounted) return;
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const ChatsPage()),
|
||||
MaterialPageRoute(builder: (context) => const RoomsPage()),
|
||||
(route) => false);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:zenith/chats.dart';
|
||||
import 'package:zenith/rooms.dart';
|
||||
import 'package:zenith/login.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:zenith/zenith_client_provider.dart';
|
||||
|
@ -66,7 +66,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
if (!savedCreds) {
|
||||
return const LoginPage();
|
||||
} else {
|
||||
return const ChatsPage();
|
||||
return const RoomsPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
77
lib/room.dart
Normal file
77
lib/room.dart
Normal file
|
@ -0,0 +1,77 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class RoomPage extends StatefulWidget {
|
||||
const RoomPage({super.key, required this.room});
|
||||
|
||||
final Room room;
|
||||
|
||||
@override
|
||||
State<RoomPage> createState() => _RoomPageState();
|
||||
}
|
||||
|
||||
class _RoomPageState extends State<RoomPage> {
|
||||
Timeline? timeline;
|
||||
|
||||
void updateTimeline() async {
|
||||
final newTimeline = await widget.room.getTimeline(
|
||||
eventContextId: widget.room.fullyRead, onUpdate: () => setState(() {}));
|
||||
setState(() {
|
||||
timeline = newTimeline;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
updateTimeline();
|
||||
widget.room.onUpdate.stream.listen((event) {
|
||||
updateTimeline();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
timeline?.cancelSubscriptions();
|
||||
widget.room.onUpdate.close();
|
||||
}
|
||||
|
||||
void sendMessage() {}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.room.getLocalizedDisplayname()),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: timeline == null
|
||||
? [const CircularProgressIndicator()]
|
||||
: [
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: timeline?.events.length,
|
||||
reverse: true,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(timeline!
|
||||
.events[index]
|
||||
.senderFromMemoryOrFallback
|
||||
.displayName ??
|
||||
""),
|
||||
subtitle: Text(timeline!.events[index].body),
|
||||
)),
|
||||
)
|
||||
],
|
||||
)),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: sendMessage,
|
||||
tooltip: 'Send message',
|
||||
child: const Icon(Icons.send),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,53 +1,62 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:zenith/zenith_client_provider.dart';
|
||||
|
||||
class ChatsPage extends StatefulWidget {
|
||||
const ChatsPage({super.key});
|
||||
|
||||
@override
|
||||
State<ChatsPage> createState() => _ChatsPageState();
|
||||
}
|
||||
|
||||
class _ChatsPageState extends State<ChatsPage> {
|
||||
final serverController = TextEditingController();
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void sendMessage() {}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: const Text("Zenith"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
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,
|
||||
tooltip: 'Send message',
|
||||
child: const Icon(Icons.send),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:zenith/room.dart';
|
||||
import 'package:zenith/zenith_client_provider.dart';
|
||||
|
||||
class RoomsPage extends StatefulWidget {
|
||||
const RoomsPage({super.key});
|
||||
|
||||
@override
|
||||
State<RoomsPage> createState() => _RoomsPageState();
|
||||
}
|
||||
|
||||
class _RoomsPageState extends State<RoomsPage> {
|
||||
final serverController = TextEditingController();
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void sendMessage() {}
|
||||
|
||||
void viewRoom(Room room) {
|
||||
Navigator.push(
|
||||
context, MaterialPageRoute(builder: (context) => RoomPage(room: room)));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: const Text("Zenith"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Center(child: Consumer<ZenithClientProvider>(
|
||||
builder: (context, provider, child) {
|
||||
if (provider.loading)
|
||||
return const CircularProgressIndicator();
|
||||
else
|
||||
return ListView.builder(
|
||||
itemCount: provider.client.rooms.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(provider.client.rooms[index]
|
||||
.getLocalizedDisplayname()),
|
||||
onTap: () => viewRoom(provider.client.rooms[index]),
|
||||
));
|
||||
},
|
||||
)),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: sendMessage,
|
||||
tooltip: 'Send message',
|
||||
child: const Icon(Icons.send),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user