2024-11-17 13:30:02 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2024-11-16 17:16:54 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gap/gap.dart';
|
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
import 'package:surface/controllers/chat_message_controller.dart';
|
|
|
|
|
|
|
|
class ChatMessageInput extends StatefulWidget {
|
|
|
|
final ChatMessageController controller;
|
|
|
|
const ChatMessageInput({super.key, required this.controller});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<ChatMessageInput> createState() => _ChatMessageInputState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ChatMessageInputState extends State<ChatMessageInput> {
|
|
|
|
final TextEditingController _contentController = TextEditingController();
|
|
|
|
final FocusNode _focusNode = FocusNode();
|
|
|
|
|
|
|
|
void _sendMessage() {
|
|
|
|
widget.controller.sendMessage(
|
|
|
|
'messages.new',
|
|
|
|
_contentController.text,
|
|
|
|
);
|
|
|
|
_contentController.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_contentController.dispose();
|
|
|
|
_focusNode.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-17 13:30:02 +00:00
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 56,
|
|
|
|
child: Row(
|
2024-11-16 17:16:54 +00:00
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
focusNode: _focusNode,
|
|
|
|
controller: _contentController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
isCollapsed: true,
|
2024-11-17 13:30:02 +00:00
|
|
|
hintText: 'fieldChatMessage'.tr(args: [
|
|
|
|
widget.controller.channel?.name ?? 'loading'.tr()
|
|
|
|
]),
|
2024-11-16 17:16:54 +00:00
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
onSubmitted: (_) {
|
|
|
|
_sendMessage();
|
|
|
|
_focusNode.requestFocus();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Gap(8),
|
|
|
|
IconButton(
|
|
|
|
onPressed: _sendMessage,
|
|
|
|
icon: Icon(
|
|
|
|
Symbols.send,
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
visualDensity: const VisualDensity(
|
|
|
|
horizontal: -4,
|
|
|
|
vertical: -4,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-11-17 13:30:02 +00:00
|
|
|
),
|
|
|
|
).padding(horizontal: 16),
|
|
|
|
],
|
2024-11-16 17:16:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|