100 lines
2.8 KiB
Dart
100 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:localization/localization.dart';
|
|
import 'package:loris/business_logic/chat/chat.dart';
|
|
import 'package:loris/partials/post_text_renderer.dart';
|
|
import 'package:loris/themes/themes.dart' as themes;
|
|
import 'package:loris/global.dart' as global;
|
|
|
|
class Chat extends StatefulWidget {
|
|
const Chat({super.key});
|
|
|
|
@override
|
|
State<Chat> createState() => _ChatState();
|
|
}
|
|
|
|
class _ChatState extends State<Chat> {
|
|
List<ConversationModel> conversations = [];
|
|
// map that stores max ids for each identity
|
|
Map<String, String?> maxIds = {};
|
|
|
|
Future<void> updateConversations() async {
|
|
final models = await getAllConversationModels(maxIds);
|
|
print(models.maxIds);
|
|
setState(() {
|
|
conversations.addAll(models.models);
|
|
maxIds = models.maxIds;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
updateConversations();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView.separated(
|
|
shrinkWrap: true,
|
|
itemBuilder: (context, index) => ConversationButton(
|
|
model: conversations[index],
|
|
),
|
|
separatorBuilder: (context, index) => const Divider(
|
|
height: themes.defaultSeperatorHeight,
|
|
color: Colors.transparent,
|
|
),
|
|
itemCount: conversations.length),
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
border: Border(
|
|
top: BorderSide(
|
|
color: Theme.of(context).colorScheme.primary, width: 2))),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class ConversationButton extends StatelessWidget {
|
|
const ConversationButton({
|
|
super.key,
|
|
required this.model,
|
|
});
|
|
final ConversationModel model;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: const BorderRadius.all(themes.defaultRadius),
|
|
color: Theme.of(context).colorScheme.surface,
|
|
),
|
|
margin: const EdgeInsets.fromLTRB(themes.defaultSeperatorHeight * 2, 0,
|
|
themes.defaultSeperatorHeight * 2, 0),
|
|
width: global.getWidth(context),
|
|
constraints: global.getConstraints(context),
|
|
child: Padding(
|
|
padding: themes.defaultInsideMargins,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Wrap(
|
|
alignment: WrapAlignment.spaceBetween,
|
|
children: [
|
|
SelectableText(model.getAccountsString()),
|
|
SelectableText("${"you-are".i18n()} ${model.identity}"),
|
|
],
|
|
),
|
|
if (model.lastStatus != null)
|
|
PostTextRenderer(input: model.lastStatus!.content),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|