Zenith/lib/room.dart

78 lines
2.1 KiB
Dart
Raw Normal View History

2023-12-29 10:40:09 +13:00
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),
),
);
}
}