Merge branch 'trunk' into windowsPerf

This commit is contained in:
Sarah Jamie Lewis 2021-06-30 16:33:40 -07:00
commit f43fdc57bb
1 changed files with 30 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cwtch/views/peersettingsview.dart';
import 'package:cwtch/widgets/DropdownContacts.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
@ -102,11 +103,13 @@ class _MessageViewState extends State<MessageView> {
}
void _sendMessage([String? ignoredParam]) {
ChatMessage cm = new ChatMessage(o: 1, d: ctrlrCompose.value.text);
Provider.of<FlwtchState>(context, listen: false)
.cwtch
.SendMessage(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).onion, jsonEncode(cm));
_sendMessageHelper();
if (ctrlrCompose.value.text.isNotEmpty) {
ChatMessage cm = new ChatMessage(o: 1, d: ctrlrCompose.value.text);
Provider.of<FlwtchState>(context, listen: false)
.cwtch
.SendMessage(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).onion, jsonEncode(cm));
_sendMessageHelper();
}
}
void _sendInvitation([String? ignoredParam]) {
@ -137,12 +140,18 @@ class _MessageViewState extends State<MessageView> {
Expanded(
child: Container(
decoration: BoxDecoration(border: Border(top: BorderSide(color: Provider.of<Settings>(context).theme.defaultButtonActiveColor()))),
child: RawKeyboardListener(
focusNode: FocusNode(),
onKey: handleKeyPress,
child: TextFormField(
key: Key('txtCompose'),
controller: ctrlrCompose,
autofocus: !Platform.isAndroid,
focusNode: focusNode,
textInputAction: TextInputAction.send,
autofocus: !Platform.isAndroid,
textInputAction: TextInputAction.newline,
keyboardType: TextInputType.multiline,
minLines: 1,
maxLines: null,
onFieldSubmitted: _sendMessage,
decoration: InputDecoration(
enabledBorder: InputBorder.none,
@ -160,13 +169,26 @@ class _MessageViewState extends State<MessageView> {
tooltip: AppLocalizations.of(context)!.sendMessage,
onPressed: _sendMessage,
),
))),
)))),
),
],
),
);
}
// Send the message if enter is pressed without the shift key...
void handleKeyPress(event) {
var data = event.data as RawKeyEventData;
if (data.logicalKey == LogicalKeyboardKey.enter && !event.isShiftPressed) {
final messageWithoutNewLine = ctrlrCompose.value.text.trimRight();
ctrlrCompose.value = TextEditingValue(
text: messageWithoutNewLine
);
_sendMessage();
}
}
void placeHolder() => {};
// explicitly passing BuildContext ctx here is important, change at risk to own health