From 0ffadc5ce98d8223d8b389d13b14384ba551d010 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 31 May 2021 14:24:09 -0700 Subject: [PATCH] Window Right Shift Bugfix + NPE on Invitation Bubble --- lib/main.dart | 3 ++- lib/widgets/invitationbubble.dart | 12 +++++++++--- lib/widgets/rightshiftfixer.dart | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 lib/widgets/rightshiftfixer.dart diff --git a/lib/main.dart b/lib/main.dart index 13731a78..4e1f94d8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:cwtch/notification_manager.dart'; +import 'package:cwtch/widgets/rightshiftfixer.dart'; import 'package:flutter/foundation.dart'; import 'package:cwtch/cwtch/ffi.dart'; import 'package:cwtch/cwtch/gomobile.dart'; @@ -101,7 +102,7 @@ class FlwtchState extends State { theme: mkThemeData(settings), // from dan: home: cwtchInit == true ? ProfileMgrView(cwtch) : SplashView(), // from erinn: home: columns.length == 3 ? TripleColumnView() : ProfileMgrView(), - home: cwtchInit == true ? (columns.length == 3 ? TripleColumnView() : ProfileMgrView()) : SplashView(), + home: cwtchInit == true ? (columns.length == 3 ? TripleColumnView() : ShiftRightFixer(child: ProfileMgrView())) : SplashView(), ), ); }, diff --git a/lib/widgets/invitationbubble.dart b/lib/widgets/invitationbubble.dart index 24b9d7ca..ea4adec6 100644 --- a/lib/widgets/invitationbubble.dart +++ b/lib/widgets/invitationbubble.dart @@ -34,11 +34,17 @@ class InvitationBubbleState extends State { prettyDate = DateFormat.yMd().add_jm().format(Provider.of(context).timestamp); } + // If the sender is not us, then we want to give them a nickname... var senderDisplayStr = ""; - if (Provider.of(context).senderOnion != null) { - var contact = Provider.of(context).contactList.getContact(Provider.of(context).senderOnion); - senderDisplayStr = contact!.nickname; + if (!fromMe && Provider.of(context).senderOnion != null) { + ContactInfoState? contact = Provider.of(context).contactList.getContact(Provider.of(context).senderOnion); + if (contact != null) { + senderDisplayStr = contact.nickname; + } else { + senderDisplayStr = Provider.of(context).senderOnion; + } } + var wdgSender = Center( widthFactor: 1, child: SelectableText(senderDisplayStr + '\u202F', diff --git a/lib/widgets/rightshiftfixer.dart b/lib/widgets/rightshiftfixer.dart new file mode 100644 index 00000000..cf4c6dac --- /dev/null +++ b/lib/widgets/rightshiftfixer.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +// From https://github.com/flutter/flutter/issues/75675#issuecomment-846601115 +// necessary to fix bug in flutter engine on Windows. +// todo: hopefully we can remove this soon +class ShiftRightFixer extends StatefulWidget { + ShiftRightFixer({required this.child}); + final Widget child; + @override + State createState() => _ShiftRightFixerState(); +} + +class _ShiftRightFixerState extends State { + final FocusNode focus = FocusNode(skipTraversal: true, canRequestFocus: false); + @override + Widget build(BuildContext context) { + return Focus( + focusNode: focus, + onKey: (_, RawKeyEvent event) { + return event.physicalKey == PhysicalKeyboardKey.shiftRight ? KeyEventResult.handled : KeyEventResult.ignored; + }, + child: widget.child, + ); + } +}