2021-11-13 10:20:09 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-01 20:14:49 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
|
2022-02-14 13:49:46 +01:00
|
|
|
import 'package:animations/animations.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2022-03-01 20:14:49 +01:00
|
|
|
import 'package:keyboard_shortcuts/keyboard_shortcuts.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2022-09-10 12:11:11 +02:00
|
|
|
import '../../widgets/m2_popup_menu_button.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
import 'chat.dart';
|
|
|
|
import 'input_bar.dart';
|
|
|
|
|
|
|
|
class ChatInputRow extends StatelessWidget {
|
|
|
|
final ChatController controller;
|
2022-02-14 13:49:46 +01:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const ChatInputRow(this.controller, {Key? key}) : super(key: key);
|
2021-11-13 10:20:09 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-02-14 13:49:46 +01:00
|
|
|
if (controller.showEmojiPicker &&
|
|
|
|
controller.emojiPickerType == EmojiPickerType.reaction) {
|
|
|
|
return Container();
|
|
|
|
}
|
2021-11-13 10:20:09 +01:00
|
|
|
return Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: controller.selectMode
|
|
|
|
? <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
height: 56,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: controller.forwardEventsAction,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
const Icon(Icons.keyboard_arrow_left_outlined),
|
2022-01-29 12:35:03 +01:00
|
|
|
Text(L10n.of(context)!.forward),
|
2021-11-13 10:20:09 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
controller.selectedEvents.length == 1
|
|
|
|
? controller.selectedEvents.first
|
2022-01-29 12:35:03 +01:00
|
|
|
.getDisplayEvent(controller.timeline!)
|
2021-11-13 10:20:09 +01:00
|
|
|
.status
|
|
|
|
.isSent
|
|
|
|
? SizedBox(
|
|
|
|
height: 56,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: controller.replyAction,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2022-01-29 12:35:03 +01:00
|
|
|
Text(L10n.of(context)!.reply),
|
2021-11-13 10:20:09 +01:00
|
|
|
const Icon(Icons.keyboard_arrow_right),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: SizedBox(
|
|
|
|
height: 56,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: controller.sendAgainAction,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2022-01-29 12:35:03 +01:00
|
|
|
Text(L10n.of(context)!.tryToSendAgain),
|
2021-11-13 10:20:09 +01:00
|
|
|
const SizedBox(width: 4),
|
|
|
|
const Icon(Icons.send_outlined, size: 16),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Container(),
|
|
|
|
]
|
|
|
|
: <Widget>[
|
2022-03-01 20:14:49 +01:00
|
|
|
KeyBoardShortcuts(
|
2022-08-14 16:59:21 +02:00
|
|
|
keysToPress: {
|
|
|
|
LogicalKeyboardKey.altLeft,
|
|
|
|
LogicalKeyboardKey.keyA
|
|
|
|
},
|
|
|
|
onKeysPressed: () =>
|
|
|
|
controller.onAddPopupMenuButtonSelected('file'),
|
|
|
|
helpLabel: L10n.of(context)!.sendFile,
|
2022-03-01 20:14:49 +01:00
|
|
|
child: AnimatedContainer(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
height: 56,
|
|
|
|
width: controller.inputText.isEmpty ? 56 : 0,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
decoration: const BoxDecoration(),
|
2022-09-10 12:11:11 +02:00
|
|
|
child: M2PopupMenuButton<String>(
|
2022-03-01 20:14:49 +01:00
|
|
|
icon: const Icon(Icons.add_outlined),
|
|
|
|
onSelected: controller.onAddPopupMenuButtonSelected,
|
|
|
|
itemBuilder: (BuildContext context) =>
|
|
|
|
<PopupMenuEntry<String>>[
|
2021-11-13 10:20:09 +01:00
|
|
|
PopupMenuItem<String>(
|
2022-03-01 20:14:49 +01:00
|
|
|
value: 'file',
|
2021-11-13 10:20:09 +01:00
|
|
|
child: ListTile(
|
|
|
|
leading: const CircleAvatar(
|
2022-03-01 20:14:49 +01:00
|
|
|
backgroundColor: Colors.green,
|
2021-11-13 10:20:09 +01:00
|
|
|
foregroundColor: Colors.white,
|
2022-03-01 20:14:49 +01:00
|
|
|
child: Icon(Icons.attachment_outlined),
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
2022-03-01 20:14:49 +01:00
|
|
|
title: Text(L10n.of(context)!.sendFile),
|
2021-11-13 10:20:09 +01:00
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
),
|
|
|
|
),
|
2021-12-22 09:45:36 +01:00
|
|
|
PopupMenuItem<String>(
|
2022-03-01 20:14:49 +01:00
|
|
|
value: 'image',
|
2021-12-22 09:45:36 +01:00
|
|
|
child: ListTile(
|
|
|
|
leading: const CircleAvatar(
|
2022-03-01 20:14:49 +01:00
|
|
|
backgroundColor: Colors.blue,
|
2021-12-22 09:45:36 +01:00
|
|
|
foregroundColor: Colors.white,
|
2022-03-01 20:14:49 +01:00
|
|
|
child: Icon(Icons.image_outlined),
|
2021-12-22 09:45:36 +01:00
|
|
|
),
|
2022-03-01 20:14:49 +01:00
|
|
|
title: Text(L10n.of(context)!.sendImage),
|
2021-12-22 09:45:36 +01:00
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
),
|
|
|
|
),
|
2022-03-01 20:14:49 +01:00
|
|
|
if (PlatformInfos.isMobile)
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'camera',
|
|
|
|
child: ListTile(
|
|
|
|
leading: const CircleAvatar(
|
|
|
|
backgroundColor: Colors.purple,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(Icons.camera_alt_outlined),
|
|
|
|
),
|
|
|
|
title: Text(L10n.of(context)!.openCamera),
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
|
|
|
),
|
2022-03-01 20:14:49 +01:00
|
|
|
if (PlatformInfos.isMobile)
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'camera-video',
|
|
|
|
child: ListTile(
|
|
|
|
leading: const CircleAvatar(
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(Icons.videocam_outlined),
|
|
|
|
),
|
|
|
|
title: Text(L10n.of(context)!.openVideoCamera),
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
|
|
|
),
|
2022-03-01 20:14:49 +01:00
|
|
|
if (controller.room!
|
|
|
|
.getImagePacks(ImagePackUsage.sticker)
|
|
|
|
.isNotEmpty)
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'sticker',
|
|
|
|
child: ListTile(
|
|
|
|
leading: const CircleAvatar(
|
|
|
|
backgroundColor: Colors.orange,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(Icons.emoji_emotions_outlined),
|
|
|
|
),
|
|
|
|
title: Text(L10n.of(context)!.sendSticker),
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (PlatformInfos.isMobile)
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'location',
|
|
|
|
child: ListTile(
|
|
|
|
leading: const CircleAvatar(
|
|
|
|
backgroundColor: Colors.brown,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(Icons.gps_fixed_outlined),
|
|
|
|
),
|
|
|
|
title: Text(L10n.of(context)!.shareLocation),
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
2022-03-01 20:14:49 +01:00
|
|
|
child: KeyBoardShortcuts(
|
2022-08-14 16:59:21 +02:00
|
|
|
keysToPress: {
|
|
|
|
LogicalKeyboardKey.altLeft,
|
|
|
|
LogicalKeyboardKey.keyE
|
|
|
|
},
|
|
|
|
onKeysPressed: controller.emojiPickerAction,
|
|
|
|
helpLabel: L10n.of(context)!.emojis,
|
2022-03-01 20:14:49 +01:00
|
|
|
child: IconButton(
|
|
|
|
tooltip: L10n.of(context)!.emojis,
|
|
|
|
icon: PageTransitionSwitcher(
|
|
|
|
transitionBuilder: (
|
|
|
|
Widget child,
|
|
|
|
Animation<double> primaryAnimation,
|
|
|
|
Animation<double> secondaryAnimation,
|
|
|
|
) {
|
|
|
|
return SharedAxisTransition(
|
|
|
|
animation: primaryAnimation,
|
|
|
|
secondaryAnimation: secondaryAnimation,
|
|
|
|
transitionType: SharedAxisTransitionType.scaled,
|
|
|
|
fillColor: Colors.transparent,
|
2022-08-14 16:59:21 +02:00
|
|
|
child: child,
|
2022-03-01 20:14:49 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Icon(
|
|
|
|
controller.showEmojiPicker
|
|
|
|
? Icons.keyboard
|
|
|
|
: Icons.emoji_emotions_outlined,
|
|
|
|
key: ValueKey(controller.showEmojiPicker),
|
|
|
|
),
|
2022-02-14 13:49:46 +01:00
|
|
|
),
|
2022-03-01 20:14:49 +01:00
|
|
|
onPressed: controller.emojiPickerAction,
|
2022-02-14 13:49:46 +01:00
|
|
|
),
|
|
|
|
),
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
2022-01-29 12:35:03 +01:00
|
|
|
if (controller.matrix!.isMultiAccount &&
|
|
|
|
controller.matrix!.hasComplexBundles &&
|
|
|
|
controller.matrix!.currentBundle!.length > 1)
|
2021-11-13 10:20:09 +01:00
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: _ChatAccountPicker(controller),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
|
|
child: InputBar(
|
2022-01-29 12:35:03 +01:00
|
|
|
room: controller.room!,
|
2021-11-13 10:20:09 +01:00
|
|
|
minLines: 1,
|
|
|
|
maxLines: 8,
|
|
|
|
autofocus: !PlatformInfos.isMobile,
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
textInputAction:
|
|
|
|
AppConfig.sendOnEnter ? TextInputAction.send : null,
|
|
|
|
onSubmitted: controller.onInputBarSubmitted,
|
|
|
|
focusNode: controller.inputFocus,
|
|
|
|
controller: controller.sendController,
|
|
|
|
decoration: InputDecoration(
|
2022-01-29 12:35:03 +01:00
|
|
|
hintText: L10n.of(context)!.writeAMessage,
|
2021-11-13 10:20:09 +01:00
|
|
|
hintMaxLines: 1,
|
|
|
|
border: InputBorder.none,
|
|
|
|
enabledBorder: InputBorder.none,
|
|
|
|
filled: false,
|
|
|
|
),
|
|
|
|
onChanged: controller.onInputBarChanged,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-06-20 15:35:22 +02:00
|
|
|
if (PlatformInfos.platformCanRecord &&
|
|
|
|
controller.inputText.isEmpty)
|
2021-11-13 10:20:09 +01:00
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: IconButton(
|
2022-01-29 12:35:03 +01:00
|
|
|
tooltip: L10n.of(context)!.voiceMessage,
|
2021-11-13 10:20:09 +01:00
|
|
|
icon: const Icon(Icons.mic_none_outlined),
|
|
|
|
onPressed: controller.voiceMessageAction,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (!PlatformInfos.isMobile || controller.inputText.isNotEmpty)
|
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: IconButton(
|
|
|
|
icon: const Icon(Icons.send_outlined),
|
|
|
|
onPressed: controller.send,
|
2022-01-29 12:35:03 +01:00
|
|
|
tooltip: L10n.of(context)!.send,
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ChatAccountPicker extends StatelessWidget {
|
|
|
|
final ChatController controller;
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const _ChatAccountPicker(this.controller, {Key? key}) : super(key: key);
|
2021-11-13 10:20:09 +01:00
|
|
|
|
|
|
|
void _popupMenuButtonSelected(String mxid) {
|
2022-01-29 12:35:03 +01:00
|
|
|
final client = controller.matrix!.currentBundle!
|
|
|
|
.firstWhere((cl) => cl!.userID == mxid, orElse: () => null);
|
2021-11-13 10:20:09 +01:00
|
|
|
if (client == null) {
|
|
|
|
Logs().w('Attempted to switch to a non-existing client $mxid');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
controller.setSendingClient(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
controller.matrix ??= Matrix.of(context);
|
|
|
|
final clients = controller.currentRoomBundle;
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: FutureBuilder<Profile>(
|
2022-05-30 13:44:05 +02:00
|
|
|
future: controller.sendingClient!.fetchOwnProfile(),
|
2022-09-10 12:11:11 +02:00
|
|
|
builder: (context, snapshot) => M2PopupMenuButton<String>(
|
2021-11-13 10:20:09 +01:00
|
|
|
onSelected: _popupMenuButtonSelected,
|
|
|
|
itemBuilder: (BuildContext context) => clients
|
|
|
|
.map((client) => PopupMenuItem<String>(
|
2022-01-29 12:35:03 +01:00
|
|
|
value: client!.userID,
|
2021-11-13 10:20:09 +01:00
|
|
|
child: FutureBuilder<Profile>(
|
2022-05-30 13:44:05 +02:00
|
|
|
future: client.fetchOwnProfile(),
|
2021-11-13 10:20:09 +01:00
|
|
|
builder: (context, snapshot) => ListTile(
|
|
|
|
leading: Avatar(
|
2021-11-20 10:42:23 +01:00
|
|
|
mxContent: snapshot.data?.avatarUrl,
|
|
|
|
name: snapshot.data?.displayName ??
|
2022-01-29 12:35:03 +01:00
|
|
|
client.userID!.localpart,
|
2021-11-13 10:20:09 +01:00
|
|
|
size: 20,
|
|
|
|
),
|
|
|
|
title:
|
2022-01-29 12:35:03 +01:00
|
|
|
Text(snapshot.data?.displayName ?? client.userID!),
|
2021-11-13 10:20:09 +01:00
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
child: Avatar(
|
2021-11-20 10:42:23 +01:00
|
|
|
mxContent: snapshot.data?.avatarUrl,
|
|
|
|
name: snapshot.data?.displayName ??
|
2022-01-29 12:35:03 +01:00
|
|
|
controller.matrix!.client.userID!.localpart,
|
2021-11-13 10:20:09 +01:00
|
|
|
size: 20,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|