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