loris/lib/pages/chat/chat.dart

90 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:localization/localization.dart';
import 'package:loris/business_logic/chat/chat.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(
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: InkWell(
child: Column(
children: [
Wrap(
children: [
SelectableText("${"you-are".i18n()} ${model.identity}")
],
)
],
),
),
);
}
}